...

View Full Version : Form Question - prevent people entering numbers?



AJW06
12-23-2006, 08:13 AM
can i prevent users from entering numbers into my HTML form.
and the opposite a code to stop people entering letter into some firelds

does anyone know the code that detects false names

whizard
12-23-2006, 04:53 PM
Not sure if this is right, but I'm taking a shot at it:

To keep numbers out


$letters_only = $_POST['letters_only'];

if (!ereg("([A-Za-z])", $letters_only)) {
//Error code here
}


To keep letters out:


$numbers_only = $_POST['numbers_only'];

if (!ereg("([0-9])", $numbers_only)) {
//Error code here
}


I'm not sure what you mean about 'detecting false names'...

What is a false name?

HTH
Dan

AJW06
12-23-2006, 08:29 PM
Well it bascically contains what you put above so numbers wouldn'yt be in a name but these might ' - understand what i mean.

whrere would i put the above code.

whizard
12-23-2006, 08:35 PM
Well it bascically contains what you put above so numbers wouldn'yt be in a name but these might ' - understand what i mean.

In other words, a 'name' could contain letters or symbols but not numbers?

Assuming that is what you mean, the code might be something like this:

name validation


$name = $_POST['name'];

if (!ereg("([0-9ANY_SYMBOLS_HERE])", $name)) {
//Error code here
}



whrere would i put the above code.

In your form handler (eg the file that receives the POST variables from your form and validates them and puts them in a database or emails them to you or whatever).

HTH,
Dan

Brandoe85
12-23-2006, 08:49 PM
All Regex aside, if your patterns aren't to complicated you may want to check out the ctype functions:
http://us2.php.net/ctype


good luck.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum