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

AnonLeo

Regular Member
Joined
Nov 23, 2013
Messages
363
Reaction score
275
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 :)
 
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.
 
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.

Oh I got it, thank you :)
 
Last edited:
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>
 
Back
Top