terungwa Posted January 29, 2014 Share Posted January 29, 2014 Regular expression for phone numbers with country code:I am trying to get the regular expression for phone number with this format: 0802-810-4000. I have come up with this regex if(!preg_match(@"^\(?([0-9]{4})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$", $_POST["phone_number"])) { // set error for phone_number field $reg_errors['phone_number'] = '<p class="warning">Phone must comply with this format: 0803-333-4000</p>'; } When i post data via my form using this phone number entry: 0802-810-4000 i get my error variable returned. What is the right regex format to use: Thanks. Link to comment https://forums.phpfreaks.com/topic/285780-regular-expression-for-phone-numbers/ Share on other sites More sharing options...
requinix Posted January 29, 2014 Share Posted January 29, 2014 Did you copy that expression from some C# code? Tsk tsk. The preg_* functions need delimiters around the expression. Delimiters such as /s. if(!preg_match("/^\(?([0-9]{4})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/", $_POST["phone_number"])) Link to comment https://forums.phpfreaks.com/topic/285780-regular-expression-for-phone-numbers/#findComment-1467003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.