1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Don't process the <form> if the <input> DOESN'T contain an underscore (HELP)!

Discussion in 'HTML & JavaScript' started by AnonLeo, Jan 20, 2014.

  1. AnonLeo

    AnonLeo Regular Member

    Joined:
    Nov 23, 2013
    Messages:
    362
    Likes Received:
    263
    Location:
    USA
    I have a <form> (http://jsfiddle.net/FEF7D/4/)
    Some users submit an ID that has only numbers in it (e.g. 981734844).
    And some users submit an ID that has underscore "_" (without quotes) in it (e.g. 28371366_243322).

    What I want to do is NOT allowing the users that submit an ID with ONLY numbers in it (e.g. 89172318) to process the form action.

    In other words:
    82174363278423: Don't allow to process the form action
    21489724893249_2918423: Allow to process the form action



    Is it possible to do that? Any ideas?



    Thanks :)
     
  2. trajek

    trajek Newbie

    Joined:
    Nov 29, 2010
    Messages:
    44
    Likes Received:
    10
    Location:
    Austin, Tx U.S.A
    Home Page:
    In your onsubmit function check the id string for the presence of the underscore character. If it contains an underscore allow it to continue. If it does not contain an underscore show an error alert and dont allow the submit to continue.
     
  3. AnonLeo

    AnonLeo Regular Member

    Joined:
    Nov 23, 2013
    Messages:
    362
    Likes Received:
    263
    Location:
    USA
    Oh I got it, thank you :)
     
    Last edited: Jan 20, 2014
  4. mypmmail

    mypmmail Junior Member

    Joined:
    Jan 31, 2008
    Messages:
    111
    Likes Received:
    27
    just adding a snippet of code that illustrate trajek's answer

    Code:
    <html>
    	<head>
    		<script src="http://code.jquery.com/jquery-latest.min.js"></script>
    		
    		<script>
    		jQuery(document).submit(function(event, data) 
    		{ 
    			if (jQuery("#id").val().indexOf("_") >= 0) {
    				alert("_ detected"); // change it to whatever message you wished to be shown.
    				return false;
    			}
    		}); 
    
    		</script>		
    	</head>
     
    	<body>
    		<form action="b.jsp" method="POST" id="myform"><br/>
    			id : <input type="id" id='id' value="1" /><br/>
    
    			<input type="submit" value="Submit" />
    		</form>
    	</body>
    </html>
    
     
    • Thanks Thanks x 1