Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
-
iffo
- Forum Commoner
- Posts: 37
- Joined: Thu Oct 05, 2006 11:56 am
Post
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
-
feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Post
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.
-
iffo
- Forum Commoner
- Posts: 37
- Joined: Thu Oct 05, 2006 11:56 am
Post
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]$/'
-
feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Post
by feyd »
viewtopic.php?t=33147 scroll to "regex modifiers"