aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes email validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "email validation" Watch "email validation" New topic
Author

email validation

MInu
Ranch Hand

Joined: Oct 09, 2003
Posts: 517
Hi..

can anyone help me to validate my forms email adress field.
i am using this code.. but it doesnt work


function validEmail(_form,_action)
{

if(document.euserForm.popUserID.value=="")
{
alert("Enter your email id");
return
}
else
{
if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.euserForm.popUserID.value)))
{

alert("The email you entered is not a valid email address.");
return
}


God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
I was at a course last month on javascript and one of the things I got was email validation, I kept this just incase I needed it again. maybe you could change your regexp string to:
/(\w*\@\w*\.\w{3})|(\w*\@\w*\.\w{2}\.\w{2})|(\w*\.\w*\@\w*\.\w{3})|(\w*\.\w*\@\w*\.\w{2}\.\w{2})/g

Davy


How simple does it have to be???
Lasse Reichstein Nielsen
Greenhorn

Joined: Feb 22, 2005
Posts: 3
Recognizing e-mail addresses is hard, bordering on impossible. The only real reference to what an e-mail address can look like is the SMTP specification (RFC 2821), and that is very forgiving. Anything on the form <localpart>@<domain> is acceptable.

I usually recommend going with just:


That accepts all of these (perfectly valid) addresses:
  • me+something@example.com
  • me.something@[192.168.10.2]
  • "Mr.Jones"@example.com


  • The parts before the "@" should only ever be interpreted by the
    receiving host, so you shouldn't try to rule something out (except
    extra "@"'s). The part after the "@" can be a domain name or an
    IP-address (both IPv4 and IPv6).

    Also remember, that there is no way to ensure that an e-mail address works, i.e., that it can receive mail, except trying to send to it and receive an answer. On the other hand, it is far too easy to reject a perfectly good and working address, which will make the user of the page a lot of pain and cursing ... not something to aim for.

    Aim to accept too much rather than too little. The worst that can happen is that the mail bounces or is lost, and that will probably happen for foo@example.com too.

    /L
     
    Don't get me started about those stupid light bulbs.
     
    subject: email validation