Page 1 of 1

Validation Regex for formbuilder...

Posted: Tue Sep 15, 2009 7:27 pm
by JeremyBASS
Thought that I'd start a place for some common patterns for people to pull from that will work in form builder...

Here is the first one..
Phone Numbers

Code: Select all


/( |^|>)
(
    (((\+|00)3[12] ?(\(0\))?)|0)    # International prefix or leading zero
    ([0-9]{2}-? ?[0-9]{7}) |        # xx-xxxxxxx
    ([0-9]{3}-? ?[0-9]{6}) |        # xxx-xxxxxx
    ([0-9]{1}-? ?[0-9]{8}) |        # x-xxxxxxxx
    ([0-9]{1}-? ?[0-9]{3}-? ?[0-9]{3}-? ?[0-9]{4}) |			# x-xxx-xxx-xxxx
    ([0-9]{1}\(? ?[0-9]{3}\)? ?[0-9]{3}-? ?[0-9]{4}) |			# x(xxx)xxx-xxxx
    (\(? ?[0-9]{3}\)? ?[0-9]{3}-? ?[0-9]{4}) |			# (xxx)xxx-xxxx
    ([0-9]{3}-? ?[0-9]{3}-? ?[0-9]{4})			# xxx-xxx-xxxx
)( |$|<)/

Note: These examples need to be turned in to one line for form builder so the first example would look like this...

Code: Select all


/( |^|>)((((\+|00)3[12] ?(\(0\))?)|0)([0-9]{2}-? ?[0-9]{7})|([0-9]{3}-? ?[0-9]{6})|([0-9]{1}-? ?[0-9]{8})|([0-9]{1}-? ?[0-9]{3}-? ?[0-9]{3}-? ?[0-9]{4})|([0-9]{1}\(? ?[0-9]{3}\)? ?[0-9]{3}-? ?[0-9]{4})|(\(? ?[0-9]{3}\)? ?[0-9]{3}-? ?[0-9]{4})|([0-9]{3}-? ?[0-9]{3}-? ?[0-9]{4}))( |$|<)/



Please feel free to post your own working patterns too :D

Cheers
Jeremy


/////////////////NOTE:
In till the new version of formbuild is out there is a 255 char limit to the regex field... _SjG_ has made the change and it will be up'ed to 1024 in the next version... for now if you need (Like the case above) you can make the change ---
line68 of modules/FormBuilder/classes/TextField.class.php

Thanks _SjG_  ;D

Re: Validation Regex for formbuilder...

Posted: Tue Sep 15, 2009 8:32 pm
by Jean le Chauve
You are THE master off regex :)

My little one :
Valid belgium's phone numbers
accept only valid belgium's phone numbers and belgium's gsm. Don't accept "-" for separation (only the first slash and points or nothing) and without International prefix.

Code: Select all

 /^[0]{1}[1-9]{1}[0-9]{0,2}[\/\.]?[0-9]{2,3}\.?[0-9]{2}\.?[0-9]{2}/

Re: Validation Regex for formbuilder...

Posted: Tue Sep 15, 2009 8:52 pm
by JeremyBASS
Jean le Chauve wrote: You are THE master off regex :)

My little one :
Valid belgium's phone numbers
accept only valid belgium's phone numbers and belgium's gsm. Don't accept "-" for separation (only the first slash and points or nothing) and without International prefix.

Code: Select all

 /^[0]{1}[1-9]{1}[0-9]{0,2}[\/\.]?[0-9]{2,3}\.?[0-9]{2}\.?[0-9]{2}/
Ha thanks but I had to be reminded to today of the or so... master of none I am... but it's one of those days :D ... I have a few more to put up in just a bit... ;D

Re: Validation Regex for formbuilder...

Posted: Tue Sep 22, 2009 4:04 am
by JeremyBASS
ok... here is another one... very experamental... the parts work... working togethet has been tested.. but I don't get much in world tests on this... but... handels every thing from UK codes to US codes to Canadian... let me know if you find an error...

world zip codes and postal codes

Code: Select all


/( |^|>)
(
    ([0-9]{4}[A-Z]{2}) |  # dutch zipcodes 1000AB | 3035KA | 9999ZZ  not -- AA1000 | Z1000 | 1000-CC
    ((?!0{5})[0-9]{5}) |        # 5 digi Us 5digi/some german'Postleitzahl'/   not -- 00000
    ([1-9]{1}[0-9]{3}\s?[A-Z]{2}) |  # Postcode for the Netherlands 1234AB 1234 AB | 1234 AB not--123BBB | 023AB
    (\d{5}-\d{4}) |        #  5 digits + 4 | 12345-6789 not 1A234 | 12345-aaaa | 12345 1234 
    ([a-zA-Z]{1}[0-9]{1}[a-zA-Z]{1}(\-| |){1}[0-9]{1}[a-zA-Z]{1}[0-9]{1}) |# Quebec's postal codes h2j-3c4 | H2J 3C4 | H2J-3c4 not-- H2J_3C4 | H213C4 | 123456
    ([0-9]{6}) | #Russian postal 150016 not-- qqww
    ([abceghjklmnprstvxyABCEGHJKLMNPRSTVXY][0-9][abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ] {0,1}[0-9][abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ][0-9]) |  # Canadian Postal Code G3M 5T9 | C3M5T9  not Z3M 5T9 | W3M 5T9 | 5T9 C3M
    ((((^[BEGLMNS][1-9]\d?) | (^W[2-9] ) | ( ^( A[BL] | B[ABDHLNRST] | C[ABFHMORTVW] | D[ADEGHLNTY] | E[HNX] | F[KY] | G[LUY] | H[ADGPRSUX] | I[GMPV] | JE | K[ATWY] | L[ADELNSU] | M[EKL] | N[EGNPRW] | O[LX] | P[AEHLOR] | R[GHM] | S[AEGKL-PRSTWY] | T[ADFNQRSW] | UB | W[ADFNRSV] | YO | ZE ) \d\d?) | (^W1[A-HJKSTUW0-9]) | (( (^WC[1-2]) | (^EC[1-4]) | (^SW1) ) [ABEHMNPRVWXY] ) ) (\s*)? ([0-9][ABD-HJLNP-UW-Z]{2})) | (^GIR\s?0AA)) # UK Postcode  W1A 1AA | EC2V 1JN | GIR 0AA not--TB12 1AB | EC2V 1JM | W2A 1AA
)( |$|<)/

with out coments...

Code: Select all


/( |^|>)(([0-9]{4}[A-Z]{2})|((?!0{5})[0-9]{5})|([1-9]{1}[0-9]{3}\s?[A-Z]{2})|(\d{5}-\d{4})|([a-zA-Z]{1}[0-9]{1}[a-zA-Z]{1}(\-| |){1}[0-9]{1}[a-zA-Z]{1}[0-9]{1})|([0-9]{6})|([abceghjklmnprstvxyABCEGHJKLMNPRSTVXY][0-9][abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ] {0,1}[0-9][abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ][0-9])|((((^[BEGLMNS][1-9]\d?) | (^W[2-9] ) | ( ^( A[BL] | B[ABDHLNRST] | C[ABFHMORTVW] | D[ADEGHLNTY] | E[HNX] | F[KY] | G[LUY] | H[ADGPRSUX] | I[GMPV] | JE | K[ATWY] | L[ADELNSU] | M[EKL] | N[EGNPRW] | O[LX] | P[AEHLOR] | R[GHM] | S[AEGKL-PRSTWY] | T[ADFNQRSW] | UB | W[ADFNRSV] | YO | ZE ) \d\d?) | (^W1[A-HJKSTUW0-9]) | (( (^WC[1-2]) | (^EC[1-4]) | (^SW1) ) [ABEHMNPRVWXY] ) ) (\s*)? ([0-9][ABD-HJLNP-UW-Z]{2})) | (^GIR\s?0AA)))( |$|<)/







also you can part this out... so if you wanted just Canadian Postal Codes... try

Code: Select all

/( |^|>)
(

 ([abceghjklmnprstvxyABCEGHJKLMNPRSTVXY][0-9][abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ] {0,1}[0-9][abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ][0-9])

)( |$|<)/




I'm sure there are lots of need... let's get these canned...  ;D

cheers

Re: Validation Regex for formbuilder...

Posted: Wed Dec 08, 2010 6:48 am
by LCarson
Regex code for Australia numbers.
No international prefix only allowance for std code.

Phone and mobile phone numbers

Code: Select all

/( |^|>)
(
([0-9]{0,2}\.? ?[0-9]{8})| 	#XX XXXXXXXX
([0-9]{10})|  			#XXXXXXXXXX
([0-9]{4}\.? ?[0-9]{6})|  	#XXXX XXXXXX
([0-9]{4}\.? ?[0-9]{3}\.? ?[0-9]{3})|  	#XXXX XXX XXX

)( |$|<)/
Single line

Code: Select all

/( |^|>)(([0-9]{0,2}\.? ?[0-9]{8})|([0-9]{10})|([0-9]{4}\.? ?[0-9]{6})|([0-9]{4}\.? ?[0-9]{3}\.? ?[0-9]{3}))( |$|<)/
Cheers