regex - VAT Number HTML5 Form Pattern -


so i've got validate european vat numbers when user registers. i've got following pattern set:

^((at)?u[0-9]{8}|(be)?0[0-9]{9}|(bg)?[0-9]{9,10}|(cy)?[0-9]{8}l|(cz)?[0-9]{8,10}|(de)?[0-9]{9}|(dk)?[0-9]{8}|(ee)?[0-9]{9}|(el|gr)?[0-9]{9}|(es)?[0-9a-z][0-9]{7}[0-9a-z]|(fi)?[0-9]{8}|(fr)?[0-9a-z]{2}[0-9]{9}|(gb)?([0-9]{9}([0-9]{3})?|[a-z]{2}[0-9]{3})|(hu)?[0-9]{8}|(ie)?[0-9]s[0-9]{5}l|(it)?[0-9]{11}|(lt)?([0-9]{9}|[0-9]{12})|(lu)?[0-9]{8}|(lv)?[0-9]{11}|(mt)?[0-9]{8}|(nl)?[0-9]{9}b[0-9]{2}|(pl)?[0-9]{10}|(pt)?[0-9]{9}|(ro)?[0-9]{2,10}|(se)?[0-9]{12}|(si)?[0-9]{8}|(sk)?[0-9]{10})$ 

and i'm clarifying in placeholder/title need to: enter vat number: cc0123456789 includes cc (country code).

however clients still don't seem understand , still fill in vat number without country code , pattern doesn't seem check if country code has been entered.

so example want people enter country code , vat number accordingly. can either enter be0123456789 or 0123456789 latter not want.

is there way have above pattern force use country code?

thanks in advance further information.

edit: solution found , optimised code further on europe countries , non europe ones well!

^(sm[0-9]{5}|(is|ch)[0-9]{6}|(atu|dk|fi|lu|mt|si|hu)[0-9]{8}|(be0|de|ee|el|gr|pt|УНП|il|rs|uz)[0-9]{9}|(pl|sk|tr|ua)[0-9]{10}|(au|it|lv|hr)[0-9]{11}|(se|ph)[0-9]{12}|(ca|id)[0-9]{15}|bg[0-9]{9,10}|cy[0-9]{8}l|cz[0-9]{8,10}|es[0-9a-z][0-9]{7}[0-9a-z]|fr[0-9a-z]{2}[0-9]{9}|gb([0-9]{9}([0-9]{3})?|[a-z]{2}[0-9]{3})|ie[0-9]s[0-9]{5}l|lt([0-9]{9,12}|[0-9]{12})|nl[0-9]{9}b[0-9]{2}|ro[0-9]{2,10}|(alk|alj)[0-9]{8}l|in[0-9]{11}(v|c)|no[0-9]{9}mva|ru[0-9]{10,12}|che[0-9]{9}(tva|mwst|iva))$ 

yes, need make country code parts obligatory.

in pattern, first (and other instances of country code) (at)? inside optional group. (...) capturing group "groups" sequence of chars. here, at. ? quantifier means at char sequence can appear 1 or 0 times. remove ( , )? , at required once.

in (el|gr)?, need remove ? quantifier since still need group match either of alternatives, el or gr.

use

^(atu[0-9]{8}|be0[0-9]{9}|bg[0-9]{9,10}|cy[0-9]{8}l|cz[0-9]{8,10}|de[0-9]{9}|dk[0-9]{8}|ee[0-9]{9}|(el|gr)[0-9]{9}|es[0-9a-z][0-9]{7}[0-9a-z]|fi[0-9]{8}|fr[0-9a-z]{2}[0-9]{9}|gb([0-9]{9}([0-9]{3})?|[a-z]{2}[0-9]{3})|hu[0-9]{8}|ie[0-9]s[0-9]{5}l|it[0-9]{11}|lt([0-9]{9}|[0-9]{12})|lu[0-9]{8}|lv[0-9]{11}|mt[0-9]{8}|nl[0-9]{9}b[0-9]{2}|pl[0-9]{10}|pt[0-9]{9}|ro[0-9]{2,10}|se[0-9]{12}|si[0-9]{8}|sk[0-9]{10})$ 

see regex demo.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -