Hyphen (-) in form value

Discussion in 'JavaScript' started by mfp, Mar 18, 2009.

  1. #1
    I need some help to create a fuction to check a Hyphen (-) sign in a form..
    like

    if (form.value.indexOf("-")
    {
    alert("Invalid Value");
    return false;
    }
    else return true;

    Any help please......
     
    mfp, Mar 18, 2009 IP
  2. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Here's an example:

    
    <script type='text/javascript'>
    function checkInput(input)
    {
    	if(input.indexOf('-') != -1)
    	{
    		alert("Invalid Value");
    		return false;
    	}
    	else
    		return true;
    }
    </script>
    <form>
    <input type='text' value='' onchange='checkInput(this.value)'>
    <input type='submit' value='Submit'>
    </form>
    
    Code (markup):
     
    xlcho, Mar 18, 2009 IP
  3. mfp

    mfp Guest

    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks brother.... :) :) i was really in need of this

    thnks..
     
    mfp, Mar 18, 2009 IP