faqts : Computers : Programming : Languages : PHP : Common Problems : Forms and User Input : Validating Data

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

15 of 16 people (94%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How to check a value from the form, to contain only digits, size from 13 to 20 characters?

Jul 16th, 2001 11:26
Rich Cavanaugh, Sheni R. Meledath, Onno Benschop,


<?php
	// get the length of the form field
	$fieldlen = strlen($HTTP_POST_VARS['formfield']);
	// check if it's greater than or equal to 13,
	// less than or equal to 20,
	// and that it is a number
	if ( (($fieldlen >= 13) && ($fieldlen <= 20)) && (is_numeric
($HTTP_POST_VARS['formfield'])) ) {
		// do stuff here if the field checks out
		echo "OK";
	} else {
		// give an error here if it doesn't
		echo "NOT OK";
	}
?>