Link to home
Start Free TrialLog in
Avatar of etechnicsit
etechnicsit

asked on

PHP Form Validation - Phone Number format - 0123456789

Hi Experts,

I need to validate the value of a text box.  The text box is for the customers phone number in the format 0123456789 (ie 10 numbers only)

The data is sent to a page (validate.php) via a forms POST method.

I want a function that will ONLY accept 10 numbers one after another, no letters or characters.

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or

if (!is_numeric(substr($_POST['phonenumber']), 0, 10))) {
  //invalid
} else {
  //valid
}

or

if (!is_numeric($_POST['phonenumber']) || 10 !== strlen($_POST['phonenumber'])) {
  //invalid
} else {
  //valid
}
Avatar of etechnicsit
etechnicsit

ASKER

Works like a charm!

Sorry ixti first in best dressed
hello i have problem in ie6.
is there any one to solve my problem..

is there any code for ie6 compatibility?

this is my site jesustv.in