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


Which one is better email pattern





imagefree
I am almost NILL in REGEX, and i always look for help when it comes to regular expressions. Few months ago, i saw the following email pattern:

Code:
/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i


but today, at php security website (http://phpsec.org/projects/guide/1.html#1.4.3) i saw the following one:

Code:
/^[^@\s<&>]+@([-a-z0-9]+\.)+[a-z]{2,}$/i


Can you please tell me which one better describes Email Addresses, and whats the difference in the above 2!
Peterssidan
I'm not sure but it looks like the first check if the part before the @ does not contain @ and spaces. the second one part is the same as the first but also check so it doesn't contain <, & and > before the @.
imagefree
Peterssidan wrote:
I'm not sure but it looks like the first check if the part before the @ does not contain @ and spaces. the second one part is the same as the first but also check so it doesn't contain <, & and > before the @.


means <, & and > are allowed to be used after @ in an email address?
Peterssidan
imagefree wrote:
means <, & and > are allowed to be used after @ in an email address?

No. Only -, a-z and 0-9 are allowed after @. and /i makes it all case insensitive.
imagefree
what does this mean at the begining?

Code:
[^@\s<&>]+
Peterssidan
The things inside [ ] describes a pattern that the string should match. the + at the end tells that it's one or more characters like this. The ^ negates the pattern and says it should not match the things after. That means it should not contain @, <, & or >. \s is whitespace characters (like space and newline and similar) so it shouldn't contain that either.
Related topics
[php scripts ] phpweather&email
Use gmail space & features for any email addr
e-ignite: Blog now updated - bigger and better than before
A question for all you monotheists.
Need help~~~
Hide Email Address With Javascript - Worth It?
[OK] How to force the filling of a email form field ?
Email!
Email Validation
Ins and Outs of Business Cards
Ins and Outs of Business Cards
asp.net email form
How relable is Email Hosted at FriHost
Password formula
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.