Hello,
Im extremely new to the world of regular expressions and need to create one for a 10 digit phone number that can have spaces dashes and brackets and a postal code that can have 6 characters and be seperated with paces or dashes. does anyone have a good site to read up on regular expressions or kind of point me in the right direction>
thanks in advance
JH
PHP and regular expression help
Moderator: General Moderators
-
flamesburn
- Forum Newbie
- Posts: 3
- Joined: Thu Aug 05, 2004 12:39 pm
Here are a few tutorials that I found, but haven't tried, so can't guarentee quality.
http://zend.com/zend/tut/tutorial-delin2.php
http://weblogtoolscollection.com/regex/regex.php
http://www.phpbuilder.com/columns/dario19990616.php3
http://www.phpfreaks.com/tutorials/52/0.php
I've been real pleased with some of the tutorials that i've found at zend.com so i'd probably try the first tutorial first
http://zend.com/zend/tut/tutorial-delin2.php
http://weblogtoolscollection.com/regex/regex.php
http://www.phpbuilder.com/columns/dario19990616.php3
http://www.phpfreaks.com/tutorials/52/0.php
I've been real pleased with some of the tutorials that i've found at zend.com so i'd probably try the first tutorial first
This program http://www.weitz.de/regex-coach/#install is very useful to test out expressions.
-
flamesburn
- Forum Newbie
- Posts: 3
- Joined: Thu Aug 05, 2004 12:39 pm
thanks
thanks for the help, the articles really help and I can definately see how that program comes in helpful. Im just really new at regular expressions.
im trying to validate a postal code i.e. N2R5A9
but I want to be able to have optional spaces and dashes for example
N2R5A9
N2R-5A9
N2R 5A9
should all validate correctly.
the pattern i have come up with does not allow for optional spaces and dashes .......
$pattern ="^[a-zA-Z][0-9][a-zA-Z][0-9][a-zA-Z][0-9]";
any thoughts? im sure its easy once i get a grasp at how to use optional characters.
im trying to validate a postal code i.e. N2R5A9
but I want to be able to have optional spaces and dashes for example
N2R5A9
N2R-5A9
N2R 5A9
should all validate correctly.
the pattern i have come up with does not allow for optional spaces and dashes .......
$pattern ="^[a-zA-Z][0-9][a-zA-Z][0-9][a-zA-Z][0-9]";
any thoughts? im sure its easy once i get a grasp at how to use optional characters.
Code: Select all
$pattern = "^\w[ -]?\d[ -]?\w[ -]?\d[ -]?\w[ -]?\d$"-
flamesburn
- Forum Newbie
- Posts: 3
- Joined: Thu Aug 05, 2004 12:39 pm
hmmm
im using ereg
is there anyway to stay along the lines of the original formatting
$pattern ="^[a-zA-Z][0-9][a-zA-Z][0-9][a-zA-Z][0-9]";
just add in a couple things?
thanks for the help
is there anyway to stay along the lines of the original formatting
$pattern ="^[a-zA-Z][0-9][a-zA-Z][0-9][a-zA-Z][0-9]";
just add in a couple things?
thanks for the help