leela Posted September 14, 2007 Share Posted September 14, 2007 Hai, I need the phone number validation using regular expression..I tried ^(\([0-9]{2,4}\))?[0-9]{9,10}$ But this allows only numbers.....But in my number.,it should allow - and + and 0-9 ( zero to nine ) characters........ Plz anyone help me.. Thanks, Leela Quote Link to comment https://forums.phpfreaks.com/topic/69293-phone-number-validation/ Share on other sites More sharing options...
jitesh Posted September 14, 2007 Share Posted September 14, 2007 You can edit according to requirments <?php $number = "+223-2231-2312"; $pattern = "/^\+{0,1}([0-9]{3,5})\-{0,1}[0-9]{3,5}\-{0,1}[0-9]{4,6}$/"; if(preg_match($pattern,$number)){ echo "Right Number"; }else{ echo "Wrong Number"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/69293-phone-number-validation/#findComment-348370 Share on other sites More sharing options...
effigy Posted September 14, 2007 Share Posted September 14, 2007 There's another example here; it doesn't include the +, but it has extensions. What are the formats you want to check for? Quote Link to comment https://forums.phpfreaks.com/topic/69293-phone-number-validation/#findComment-348385 Share on other sites More sharing options...
leela Posted September 19, 2007 Author Share Posted September 19, 2007 Thanks alot.. The first format is fine.. Leela Quote Link to comment https://forums.phpfreaks.com/topic/69293-phone-number-validation/#findComment-351024 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.