View Full Version : validating user input

10-24-2006, 01:33 PM

i have a form which contains some textboxes for name,email,phone,address.the user will enter some values in that.i want to validate them.how to do it.i want to validate the user so that he can enter name in name textbox and number in phone textbox and in email.could you please tell me how to validate this.i want to avoid malicious characters entered by user

10-24-2006, 01:39 PM
does this help

if(!$email == "" && (!strstr($email,"@") || !strstr($visitormail,".")))
echo "<h2>Go Back & Enter A Valid Email Address</h2>";

10-24-2006, 04:55 PM
you should use function "empty()" to check that form fields aren't empty and for checking the phone field you should use "is_numeric()". You can also add a mail verification method (confirming whatever it is by sending a mail which requires to be answered).

Hope i was usefull

I also think using validation image is a good addittion (avoid spam). if you are unfamiliar with it you can look at my subscription page in www.thesudokuvalley.com

10-24-2006, 05:16 PM
And use trim();
When you entered a space, the input field it's not empty anymore but the filled in space is not relevant.

10-24-2006, 06:04 PM
Use preg_match to check for invalid characters. For example, if you wanted to allow only numbers to be input then you could something like this:

if (preg_match ('[^0-9]',$input))
die ('You can only enter numbers');
// Do whatever you need with the input.