FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Form validation





PatTheGreat42
I recently scripted a web form in PHP and, of course, included some form validation. One of the things I did was check the email to see if it included the "@" sign. However, the only way I could figure out how to do it was to use "strstr($_POST['email'],"@")," and see if it returns anything. If the return is FALSE, I know that they didn't include an @ sign. It works just peachy, but is there a better way to do this?
mathiaus
I use this
Code:
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$_POST['email'])){
<<<ERROR>>>
} else {
<<REST OF FORM VALIDATION>>
}

This checks the @ symbol was used, a domain was given and no invalid characters are used.

The best way to validate an email is to create an account though, send an email with a link which actives that account.
dandelion
See also: Check email format.
Grimboy
On the other hand you have email validation to properly verify this and regex is slow and hard to read.
Related topics
check box validation
HTML
Easily create forms and many other stuff without much knowle
Java tutorials
A very good PHP MySQL Tutorial
Help with User Form Validation
Java Script City
Use Javascript to Validate from
AJAX coding prob
Form validation, seperate file, or same as form?
please please beta test it (PHP coders)
Great validation tool!
Form Processing
Simple Form Validation [solved]
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.