Still, if you use this, understand that it is not infallible.(sp?) All it does is screen out someone from typing "dga;sfgharggnjg" into the email box. a@b.c would beat the script, as would 1@2.3. But, this script is still great at screening out some nonsense submissions.
a@b.c would beat the script, as would 1@2.3. But, this script is still great at screening out some nonsense submissions.
Nope. The regular expression says that there must be two to four characters after the @ symbol and that they must be alphabetic. I have this code in place in my contact form, and both your examples don't skirt my edits.
What might be interesting is using the Validate PEAR package. I haven't tried that, but it's supposed to somehow validate the domain as well as the email address.
Nope. The regular expression says that there must be two to four characters after the @ symbol and that they must be alphabetic. I have this code in place in my contact form, and both your examples don't skirt my edits.
What might be interesting is using the Validate PEAR package. I haven't tried that, but it's supposed to somehow validate the domain as well as the email address.
Actually I believe it's 2-4 chars after the period for the TLD. 1@2.aa would work.
There also needs to be a clause written into the regex to allow an additional period and 2-4 chars for domains such as .co.uk. I wrote the clause below:
PHP Code:
$email = trim($email);
if (preg_match('/^[a-z0-9._-]+@[a-z0-9._-]+\.([a-z]{2,4})($|\.([a-z]{2,4})$)/i', $email)) {
// code to send e-mail goes here
}
It's becouse the .co matches with the "[a-z0-9._-]+" part just after the @.
From: email@site.co.uk
it matches like this:
[a-z0-9._-]+ => email
@ => @
[a-z0-9._-]+ => site.co
\. => .
([a-z]{2,4}) => uk
__________________
I'm not sure if this was any help, but I hope it didn't make you stupider.
Experience is something you get just after you really need it. PHP Installation Guide Feedback welcome.
It'd probably be best to modify it to comply to RFC 2822, which is more or less the rules as to what is, and what isn't a valid email address. Examples are: user@example.com, User <user@example.com>
It's becouse the .co matches with the "[a-z0-9._-]+" part just after the @.
From: email@site.co.uk
it matches like this:
[a-z0-9._-]+ => email
@ => @
[a-z0-9._-]+ => site.co
\. => .
([a-z]{2,4}) => uk
Nope. The regular expression says that there must be two to four characters after the @ symbol and that they must be alphabetic. I have this code in place in my contact form, and both your examples don't skirt my edits.
Sorry, I misread the code.
Quote:
Originally Posted by vinyl-junkie
Proving once again that I'm terrible about interpreting regular expressions.