SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
-
Nov 18, 2009, 21:53 #1
- Join Date
- Mar 2008
- Posts
- 22
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Please help with this regular expression preg_match()
Is there anyway to force a specific string format?
For example this requires numbers and no leading zeros.
Code:^[1-9][0-9]+$
Also for height, would it be possible to force the ' (hyphen) and " (quotes) in a format like 5'11"?
Any help will greatly be appreciated.
-
Nov 18, 2009, 22:05 #2
- Join Date
- Jan 2009
- Location
- Surrey BC, Canada
- Posts
- 309
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This should do it.
Code:^[0-9]'[0-9]{1,2}"$
For your pound issue, useCode:^[1-9]{1}[0-9]*lbs$
-
Nov 19, 2009, 04:00 #3
-
Nov 19, 2009, 04:18 #4
- Join Date
- Jan 2009
- Location
- Surrey BC, Canada
- Posts
- 309
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The first doesn't really NEED the {1}, but the difference between the two is that the first range excludes 0, making leading zeroes fail the match.
-
Nov 19, 2009, 04:23 #5
-
Nov 19, 2009, 04:35 #6
- Join Date
- Jan 2009
- Location
- Surrey BC, Canada
- Posts
- 309
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ah. Yes, there really isn't one.
-
Nov 19, 2009, 05:51 #7
Bookmarks