Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validate phone number

Status
Not open for further replies.

Sajtz

IS-IT--Management
Apr 23, 2002
75
EU
Hi!
I'm a php newbee, trying to validate a phone number from a form. The following code is in the checknr.php file.

// check phone for validity
if (($PHONE_NO) || ($phone_no)) {
$phone_no = trim($phone_no);
if ($PHONE_NO)
$phone_no = trim($PHONE_NO);
if (!ereg("[0-9])", $phone_no)) {
print_error("your nr is not valid. Example of a valid phone nr. 091016750");
}
}

I don't know what to type in the "(!ereg("[0-9])" part of the code. The phone number can only be of a numeric value (0123456789)or like this (0910-1235478).

 
"[0-9-]{10}" would limit it to 10 characters. "[0-9-]+" for no limit. //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top