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?
Form validation
I use this
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.
| 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.
See also: Check email format.
On the other hand you have email validation to properly verify this and regex is slow and hard to read.
