How to verify if '@' is in a string?!

Discussion in 'JavaScript' started by redhits, Mar 10, 2008.

  1. #1
    Ok


    I am having an input type=text name=email


    and i would like to verify if it's having the '@' sign on it.
    How i can do this?!

    Please help !
     
    redhits, Mar 10, 2008 IP
  2. johngalt192

    johngalt192 Guest

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use the IndexOf function to test for '@'.

    For example,

    if (form.email.value.indexOf('@')>0) alert('Email contains @')

    You will want to modify this to your needs based upon your field's actual name (e.g. It may not be located in a form named 'form'), and how you want to use the result of the test.
     
    johngalt192, Mar 10, 2008 IP