Regular expresions...
Moderator: General Moderators
I found this one tutorial I really did understand: http://www.sitepoint.com/article/974/
The only thing is, the script validates the email address if you enter 2 dot's like so: info@mandio..com
I dunno how to add an extra bit in there to say only allow 1 dot:
here's my code:
I still don't really get certain bits about the preceding characters but I am getting there. I have always been very scared of regular expressions since I began my programming career 5 years ago using ASP and I just used to use a simple replace function... 
The only thing is, the script validates the email address if you enter 2 dot's like so: info@mandio..com
I dunno how to add an extra bit in there to say only allow 1 dot:
here's my code:
Code: Select all
else{
if(!ereg("^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z.]{2,5}$", $F_email)){
$errors[] = "You have entered an invalid <b>e-mail</b> address";
}i started programming by manipulating programs written in basic/truebasic for the appple2e as a child... really got into it in college.. first thing i formally learned was java/c (both concurrently and 5 yrs ago now)
i'm hesitant to call php/asp programming languages because of how they are made in comparison to what i think of as programming languages...
i know there's something in php to validate e-mail addresses. check out the oreilly books. it's in the cookbook...brb
i'm hesitant to call php/asp programming languages because of how they are made in comparison to what i think of as programming languages...
i know there's something in php to validate e-mail addresses. check out the oreilly books. it's in the cookbook...brb
ok.. here it is. pg 352-355....
section 13.5
problem: checking to see if an e-mail is valid
solution: there's no way to be completely sure without trying the address, but to weed out typos, there's several patterns. if the IMAP extension is enabled, you can use imap_rfc822_parse_adrlist():
the pattern they suggest:
/^[^@\s+@([-a-z0-9]+\.)+[a-z]{2,}$/i
they other pattern they give is
/^[^@\s]+@([-a-z0-9]+\.)+([a-z]{2}|com|net|edu|org|gov|mil|int|biz|pro|info|arpa|aero|coop|name|museum)$/ix
both of their patters only really look at what's after the at. the pattern i made, which seems to do what you want, also checks the begining has no spaces (both of these don't from the write up)
if(!(preg_match('/[\w\.\-]+@[\w\.\-]+\.\w\w\w?/', $email))){$err=TRUE; $errs[]='Your E-Mail address does not appear to be valid'; $step=2;}
that uses perl's regular expression instead of the posix one.
it looks for any number of the characters in \w (A-Z,a-z,0-9,_) . and - repreated any number of times, followed by an @ followed by the first thing again until .\w\w with an optional 3rd, so that it gets all the 2 letter names and 3 letter names.
section 13.5
problem: checking to see if an e-mail is valid
solution: there's no way to be completely sure without trying the address, but to weed out typos, there's several patterns. if the IMAP extension is enabled, you can use imap_rfc822_parse_adrlist():
Code: Select all
$parsed=imap_rfc822_parse_adrlist($email_address, $default_host);
if('INVALID_ADDRESS'==$parsed['mailbox']{
#badaddress
}/^[^@\s+@([-a-z0-9]+\.)+[a-z]{2,}$/i
they other pattern they give is
/^[^@\s]+@([-a-z0-9]+\.)+([a-z]{2}|com|net|edu|org|gov|mil|int|biz|pro|info|arpa|aero|coop|name|museum)$/ix
both of their patters only really look at what's after the at. the pattern i made, which seems to do what you want, also checks the begining has no spaces (both of these don't from the write up)
if(!(preg_match('/[\w\.\-]+@[\w\.\-]+\.\w\w\w?/', $email))){$err=TRUE; $errs[]='Your E-Mail address does not appear to be valid'; $step=2;}
that uses perl's regular expression instead of the posix one.
it looks for any number of the characters in \w (A-Z,a-z,0-9,_) . and - repreated any number of times, followed by an @ followed by the first thing again until .\w\w with an optional 3rd, so that it gets all the 2 letter names and 3 letter names.