Title |
Test
Find
Pattern Title
|
Expression |
^\(0[1-9]{1}\)[0-9]{8}$ |
Description |
This is used to validate an Australian telephone number with no other characters than the () being used. Validates area code being between 01 - 09. |
Matches |
(02)12341234 | (03)12341234 | (05)12341234 |
Non-Matches |
00 1234 1234 | 00-1234-1234 | (00)12341234 |
Author |
Rating:
Barry Pranklin
|
Source |
|
Your Rating |
|
Title: Missing validating a heap of numbers
Name: Lloyd Borrett
Date: 2/2/2006 10:46:19 PM
Comment:
This expression doesn't handle all sorts of valid Australian phone numbers. To do that you need more than one regular expression. Something like...
//
// Function to check an Australian phone number is valid.
//
function is_valid_phone ($strPhone) {
$isValid = false;
// Strip blanks, brackets, periods, dashes and plus
$strPhone = str_replace(array('(', ')', '-', '+', '.', ' '), '', $strPhone);
// Check 10 or 11 digits
switch (strlen($strPhone)) {
case "6":
if (ereg('^(13[0-9]{4})$', $strPhone)) {
$isValid = true;
}
break;
case "7":
if (ereg('^(180[0-9]{4})$', $strPhone)) {
$isValid = true;
}
break;
case "10":
if (ereg('^(((01|02|03|04|07|08|12|19)[0-9]{8})|(1300[0-9]{6})|(180[0-9]{7}))$', $strPhone)) {
$isValid = true;
}
break;
case "11":
if (ereg('^(61(1|2|3|4|7|8)[0-9]{8})$', $strPhone)) {
$isValid = true;
}
break;
default:
$isValid = false;
}
return $isValid;
}