775 snippets from 1546 members, and growing!
|
login
|
join
about
bytebin
members
tags
snippets
join
Snippets
Submit a Snippet
Search Snippets
New Snippets
Top Snippets
Top Tags
PHP
(136)
JavaScript
(123)
Java
(66)
VBSCRIPT
(58)
String
(44)
CSS
(31)
CSharp
(28)
File
(28)
HTML
(27)
C
(24)
mysql
(24)
VB.NET
(24)
python
(24)
CPlusPlus
(23)
groovy
(23)
New Snippets
Top 15 Ways To Ma...
Top 15 Ways To Ma...
Top 15 Ways To Ma...
Top 15 Ways To Ma...
Top 15 Ways To Ma...
Very lightweight ...
AutoComplete plug...
AutoComplete plug...
Connection Java -...
View PostgreSql
Venture Capital Jobs
New Members
NationalCollection
me
jamesmcm
Can
Kelmi
ysg
dannymo2
chorny
wallie
Hackdemian
Top Members
dannyboy
sundaramkumar
mattrmiller
Pio
i_kenneth
ASmith
ctiggerf
sehrgut
bertheymans
SCoon
Home
/
Snippets
/
Simple email validation
/
Comments
Simple email validation
Snippet Menu
Revisions
Comments
Related Snippets
Add to Favorites
Email Snippet
Download Snippet
Print Snippet
Blog Snippet
snippet
|
revisions
|
comments
|
related
|
Add to Favorites
|
email
download
|
print
|
blog it
New Comment
Oops
Tue. Sep. 5th, 2006 10:48 PM
mceppi
I voted down, but the code looks good, it should be a plus 1 from me.
Reply
Isn't valid
Wed. Oct. 18th, 2006 2:31 PM
snevine
Check your containers for your TLD parsing... ([a-zA-Z0-9]{2,4})+ would match [a-zA-Z0-9] one to inf times. It shouldn't be encapsulated at all.
Also, you have the host and sub host separation parsing good, but the local name parsing allows an infinite number of periods in a row.
-CB
# Somewhat better validation
$email
=~ /^
[
\w\+-
]
+
(
\.
[
\w\+-
]
+
)
*@
[
\w-
]
+
(
\.
[
\w-
]
+
)
*\.\w
{
2
,
4
}
$/;
# Much better validation per RFC 822 & RFC 2822
$email
=~ /^
[
\w,!
#$%&'*+\/=?^`{|}~-]+(\.[w,!#$%&'*+\/=?^`{|}~-]+)*@[\w-]+(\.[\w-]+)*\.[\w]{2,}$/;
# You could also allow for the standardized maximum lengths...
Reply
e-mail validation
Mon. Feb. 11th, 2008 6:13 PM
chorny
Email::Valid
on CPAN has much better capabilities, and won't fail on .museum.
---
Sasha Chorny,
http://chorny.net
Reply
New Comment
Also, you have the host and sub host separation parsing good, but the local name parsing allows an infinite number of periods in a row.
-CB
# Somewhat better validation
$email =~ /^[\w\+-]+(\.[\w\+-]+)*@[\w-]+(\.[\w-]+)*\.\w{2,4}$/;
# Much better validation per RFC 822 & RFC 2822
$email =~ /^[\w,!#$%&'*+\/=?^`{|}~-]+(\.[w,!#$%&'*+\/=?^`{|}~-]+)*@[\w-]+(\.[\w-]+)*\.[\w]{2,}$/;
# You could also allow for the standardized maximum lengths...
---
Sasha Chorny, http://chorny.net