Page 1 of 1

regex validation help needed

Posted: Thu Nov 09, 2006 7:49 am
by iffo
Hi,

I have to validate canadian zip code which are in this format
L1T3H9 always 6 characters

total five characters ,
alpha numner alpha number alpha number




I am doing like the folowing, but it is not working, what di i need to do so that unless I have exact same format it fails


'regex' => '/^[A-Za-z][0-9][A-Za-z][0-9][A-Za-z][0-9]{6,6}$/'

thanks

Posted: Thu Nov 09, 2006 8:00 am
by feyd
Lose the {6,6}. You may also want to use the "s" modifier for the entire pattern to make sure it's only a single line.

Posted: Thu Nov 09, 2006 8:20 am
by iffo
sorry I am very new to regex what is s modifier ? , i removed the {6,6}

'regex' => '/^[A-Za-z][0-9][A-Za-z][0-9][A-Za-z][0-9]$/'

Posted: Thu Nov 09, 2006 1:31 pm
by feyd
viewtopic.php?t=33147 scroll to "regex modifiers"