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.
etechnicsitAsked:
Who is Participating?
 
RoonaanConnect With a Mentor Commented:
Here you go:

if(!preg_match('/^\d{10}$/', $_POST['phonenumber'])) {
  //invalid
} else {
  //valid
}

-r-
0
 
ixtiCommented:
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
}
0
 
etechnicsitAuthor Commented:
Works like a charm!

Sorry ixti first in best dressed
0
 
whspiderCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.