Solved

PHP Form Validation - Phone Number format - 0123456789

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

839 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