Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: preg_match tells me numbers are symbols!

Started 1 month, 1 week ago by fisicx
A very noob here. I've searched the forum and found lots of good posts but not one that exactly matches my problem so here it is. All I want to do is check for symbols in a telephone number. I pick up the variable from the form and check it like this: function VerifyForm(&$values, &$errors) { if(!preg_match("[^0-9]",$values['telephone'])) $errors['telephone'] = 'no symbols';...
Site: PHPBuilder.com  PHPBuilder.com - site profile
Forum: Coding  Coding - forum profile
Total authors: 4 authors
Total thread posts: 9 posts
Thread activity: no new posts during last week
Domain info for: phpbuilder.com

Other posts in this thread:

NogDog replied 1 month, 1 week ago
I don't think you want to negate ("!") the preg_match(), as you want the if condition to be true if it finds anything that is not a 0-9, correct?

fisicx replied 1 month, 1 week ago
That's correct, I hadn't realised the ! negated everything. If this is the case how come it negates the 0-9 and the letters and symbols?

jaql replied 1 month, 1 week ago
Quote: Originally Posted by fisicx That's correct, I hadn't realised the ! negated everything. If this is the case how come it negates the 0-9 and the letters and symbols? [^0-9] matches any character except for 0 through 9 Code: /^[2-9]\d{2}-\d{3}-\d{4}$/ If it helps, the above regex will match ...

fisicx replied 1 month ago
Thanks jaql, I think I'm going bonkers here. This should be such a simple check so I must be missing something. What I want to do is check the whole string for anything other than 0-9, the symbols +-() and a space. If there is an match then the error message asks the user to check their telephone number. I could easily strip out the offending characters but I'm trying to be a ...

jaql replied 1 month ago
Try this: PHP Code: $pattern = '/((\(\d{3}\)?)|(\d{3}))([\s-+]?)(\d{3})([\s-]?)(\ d{4})/' ; if(! preg_match ( $pattern , $number )) { // error code } else { // success }

nrg_alpha replied 1 month ago
Quote: Originally Posted by fisicx Thanks jaql, What I want to do is check the whole string for anything other than 0-9, the symbols +-() and a space. If there is an match then the error message asks the user to check their telephone number. I could easily strip out the offending characters but I'm trying to be a little more ...

fisicx replied 1 month ago
Thanks eveyone for their help. It's all sorted now due to my complete ignorance on how regular expressions work. however with your suggestions and lots of reading I got it to do just what I want! It now checks for an empty string and checks for the dodgy charaters in the string. I've set it to allow 0-9 -+() and spaces. It doens't check for formatting because as suggested tyhis can have...

fisicx replied 1 month ago
Sorted Thanks eveyone for their help. It's all sorted now due to my complete ignorance on how regular expressions work. however with your suggestions and lots of reading I got it to do just what I want! It now checks for an empty string and checks for the dodgy charaters in the string. I've set it to allow 0-9 -+() and spaces. It ...

 

Top contributing authors

Name
Posts
fisicx
5
user's latest post:
preg_match tells me numbers are...
Published (2009-11-09 06:20:00)
Thanks eveyone for their help. It's all sorted now due to my complete ignorance on how regular expressions work. however with your suggestions and lots of reading I got it to do just what I want! It now checks for an empty string and checks for the dodgy charaters in the string. I've set it to allow 0-9 -+() and spaces. It doens't check for formatting because as suggested tyhis can have so many variants. So you will get one of...
jaql
2
user's latest post:
preg_match tells me numbers are...
Published (2009-11-04 08:56:00)
Try this: PHP Code: $pattern = '/((\(\d{3}\)?)|(\d{3}))([\s-+]?)(\d{3})([\s-]?)(\d{4})/' ; if(! preg_match ( $pattern , $number )) {    // error code } else {    // success }
NogDog
1
user's latest post:
preg_match tells me numbers are...
Published (2009-11-02 20:21:00)
I don't think you want to negate ("!") the preg_match(), as you want the if condition to be true if it finds anything that is not a 0-9, correct?
nrg_alpha
1
user's latest post:
preg_match tells me numbers are...
Published (2009-11-04 22:57:00)
Quote: Originally Posted by fisicx Thanks jaql, What I want to do is check the whole string for anything other than 0-9, the symbols +-() and a space. If there is an match then the error message asks the user to check their telephone number. I could easily strip out the offending characters but I'm trying to be a little more helpful. Suggestion please? My suggestion would be to strip out offending characters, look at what numbers you...

Related threads on "PHPBuilder.com":

Related threads on other sites:

Thread profile page for "preg_match tells me numbers are symbols!" on http://www.phpbuilder.com. This report page is a snippet summary view from a single thread "preg_match tells me numbers are symbols!", located on the Message Board at http://www.phpbuilder.com. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity