How to validate phone number using php
This link has a good example for your issue. You may need to change a bit to accommodate your country's phone format.
http://www.plasticbrain.net/resources/php-validate-email-address-and-phone-number/
Phone numbers on mars have 15 digits and they start with ~
. So check the input string if it starts with ~
and have length 15 with all trailing numerics.
Since phone numbers must conform to a pattern, you can use regular expressions to match the entered phone number against the pattern you define in regexp.
php has both ereg and preg_match() functions. I'd suggest using preg_match() as there's more documentation for this style of regex.
An example
$phone = '000-0000-0000';
if(preg_match("/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/", $phone)) {
// $phone is valid
}
I depends heavily on which number formats you aim to support, and how strict you want to enforce number grouping, use of whitespace and other separators etc....
Take a look at this similar question to get some ideas.
Then there is E.164 which is a numbering standard recommendation from ITU-T