Solved

PHP Form Validation - Phone Number format - 0123456789

Posted on 2006-06-27
4
5,658 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
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now