SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
-
Jan 29, 2007, 09:12 #1
javascript validation for email address
what is the javascript validation for the email address like
php.ycho@gmail.com
i used the simple validation like
"^\\w{1,}@\\w{1,}(\\.\\w{1,}){1,}$"
which works well for php@gmail.com but doesnot work for php.ycho@gmail.com
can anybody make a modification to above pattern to work for php.ycho@gmail.com
Thanks in advance to all of you
-
Jan 29, 2007, 09:33 #2
- Join Date
- Dec 2004
- Location
- At My Desk!!
- Posts
- 1,642
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
just as a small note to remember that if the user has javascript turned off then the email address will not be validated, its better to use a server side language to do this.
"Am I the only one doing ASP.NET in Delphi(Pascal)?"
-
Jan 29, 2007, 09:45 #3
Actually i dont have so much knowledge in regex....
and i have to do the work withing hour...and i thought forum is the best place..
Please help me in such case..
i appreciate for any help
-
Jan 29, 2007, 15:19 #4
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
I generally use
Code:emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
"my email"@somewhere.com
me@[10.2.56.100]
I usually use the same expression in both Javascript and PHP.Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
Jan 30, 2007, 00:58 #5
- Join Date
- Jan 2007
- Location
- Kathmandu, Nepal
- Posts
- 47
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Try this one :
var goodEmail = form.txtemail.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
if (!goodEmail)
{
alert("The Email address you entered is invalid please try again!")
form.txtemail.focus()
return (false);
}Visit www.rusagar.com
-
Jan 30, 2007, 01:43 #6
- Join Date
- Dec 2006
- Location
- Prague
- Posts
- 210
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Your regexp not work for national domains, I use this one
Code:^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$
-
Jan 30, 2007, 03:12 #7
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
museum is the longest of the current top level domain names - all of the others are 2, 3, or 4 characters with the 2 character ones being country specific (eg. .tv for Tuvala) and the others being the generic ones I included in my expression above.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
Jan 30, 2007, 03:51 #8
- Join Date
- Apr 2001
- Location
- Devon, UK
- Posts
- 333
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The regex I use is fairly generic:
/^.+@[a-z0-9]+([_\.\-]{0,1}[a-z0-9]+)*([\.]{1}[a-z0-9]+)+$/
As far as I'm aware, the name before the @ sign can be almost anything - even a single space character.
Bookmarks