![]() |
Regular Expressions
I'm having trouble with regular expressions. I think I have done something wrong within them since they're accepting the data even if they don't match the pattern.
$pattern = '/^[0-9]{3}$/'; suppose to match 000$pattern = '/^[0-9]{3}\-[0-9]{3}\-[0-9]{3}$/'; suppose to match 000-000-00$pattern = '/^[0-9]{5}$/'; suppose to match 00000$pattern = '/^www\.[a-zA-Z0-9\-]+\.([a-zA-Z\.]{2,4})$/'; - suppose to match www.domain.ext.(w/e)Help :( |
Can you put these patterns into context? It might be more a problem with how you're using them than than the patterns themselves.
|
Can you elaborate your requirements?
|
I think Salathe was trying to ask how you were trying to use these patterns, as some of them seem to be fine. Here's a quick script I wrote to test each pattern:
PHP Code:
|
Don't forget the .org.uk extension which is 7 :)
|
Example use:
PHP Code:
|
I've had to shrink down the function a lot as it's getting values from your class. This works fine for me though which is a skeleton adaptation of your function:
PHP Code:
$this->getValue($field); is returning a value that is not a zip code - var_dump($field); it and see. |
| All times are GMT. The time now is 09:18 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0