1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Validating Email ?

Discussion in 'JavaScript' started by priyakochin, Jul 4, 2008.

  1. #1
    priyakochin, Jul 4, 2008 IP
  2. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #2
    function isValidEmail(S)
    {
    return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(S);
    }

    use it like this

    if( !isValidEmail(document.getElementById('someformelement').value) )
    {
    alert('invalid email');
    }
     
    serialCoder, Jul 4, 2008 IP
  3. =Messa=

    =Messa= Peon

    Messages:
    104
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Take note, serialCoder's code won't properly validate all e-mail addresses.

    Especially those containing "+" in the part of an e-mail address string before "@" delimiter.

    Most of the websites and e-mail providers do not even know about "+" is normally allowed there and mark it as invalid character, which is wrong and is against RFC.

    Also, it won't validate e-mail addresses with TLD longer than 3 characters, which is also completely wrong, because there are TLD's longer than 3 characters, such as "info" or "mobi".

    So, if the website you need this for is properly coded and your SMTP is not violating RFC, you should use at least the RegExp string I provide below.

    Anyway, I'd recommend you to create or pay someone to create more robust solution for you.

    return /^\w+[\+\.\w-]*@\w+([\.-]?\w+)*(\.\w{2,6})+$/.test(S);
    Code (markup):
     
    =Messa=, Jul 4, 2008 IP
  4. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #4
    darn, they allow + in the email addresses??

    well, anyways its something i just typed up :)
    thanks for pointing it out

     
    serialCoder, Jul 4, 2008 IP