Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

input validation

Status
Not open for further replies.

HOTLIPS

Technical User
Dec 5, 2000
55
GB
Hi
I want to check that part of a string... which is a part number... which is input by a user is an integer.
The part number starts with P or A then has a 6 digit number....my problem...I want to check that the 6 digits are numbers and not letters.
If say the number P45 is entered .. My program front fills the input number with zeros..hence P000045 would be the correct number and accepted... but I want to make sure of the digits ....so if the number entered is say P45T...I want to reject it and inform the user of an invalid entry.
Can anyone help
 
I'd use a regular expression.

The statement:

$value = preg_match ('/^[PA]\d{1,6}$/i', $_POST['foo']);

will set $value to a 1 if the string is comprised of exactly an A or a P followed by 1 through 6 digits. It performs the check case insensitively.


Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top