Need 1 condition in js

Discussion in 'JavaScript' started by katalin, Dec 8, 2009.

  1. #1
    I have the following code:
    
    if (document.contact.email.value == "") {
    		msg = msg+ "- Your Email Address \n";
    	}
    
    Code (markup):
    I need that field not empty and it must contain @ and .
    I hope you understand!
     
    katalin, Dec 8, 2009 IP
  2. Jim_

    Jim_ Peon

    Messages:
    72
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if (document.contact.email.value == "" || document.contact.email.value.indexof("@") < 0 || document.contact.email.value.indexof(".") < 0) {
    		msg = msg+ "- Your Email Address \n";
    	}
    Code (markup):
    something like this should work
     
    Jim_, Dec 8, 2009 IP
  3. gacba

    gacba Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    There are also numerous regex scripts you can find on Google. Try Googling "email validation regex" or something similar if you're looking for something more robust.
     
    gacba, Dec 8, 2009 IP
  4. myst_dg

    myst_dg Active Member

    Messages:
    224
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #4
    myst_dg, Dec 8, 2009 IP