Solved

PHP Form Validation - Phone Number format - 0123456789

Posted on 2006-06-27
4
5,673 Views
Last Modified: 2009-09-24
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.
0
Comment
Question by:etechnicsit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 100 total points
ID: 16998863
Here you go:

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

-r-
0
 
LVL 6

Expert Comment

by:ixti
ID: 16998968
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
 

Author Comment

by:etechnicsit
ID: 16998990
Works like a charm!

Sorry ixti first in best dressed
0
 

Expert Comment

by:whspider
ID: 25411405
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

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question