This regular expression allows anything that starts with a "+" and 1-3 digits for the country code, followed by an optional "-" or space, followed by an optional digit in brackets (typically 0) followed by either two or three blocks of 1-7 digits.
function invalidPhoneNumber($str) {
if (preg_match("/^(\+\d{1,3}(-| )?\(?\d\)?(\s?\d{1,7}){2,3})$/", $str)) return false;
else return true;
}
function invalidPhoneNumber(str) {
if (str.match(/^(\+\d{1,3}(-| )?\(?\d\)?(\s?\d{1,7}){2,3})$/)) return false;
else return true;
}
>> Posted in Websites at 14:02, and viewed 8,045 times
Next article: Hiding email addresses with PHP (04 March 2009)
Next Websites article: Creating Multipart Emails in PHP (15 June 2009)
Add your comments