wood burning stoves
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
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "email validation" Watch "email validation" New topic

email validation

Ranch Hand

Joined: Oct 09, 2003
Posts: 517

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

function validEmail(_form,_action)

alert("Enter your email id");

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

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:


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

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@[]
  • "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.

    I agree. Here's the link: http://aspose.com/file-tools
    subject: email validation
    It's not a secret anymore!