Input Box Restrictions Javascript
Javascripts > Javascript Forms > Input Box Restrictions
Script Title: Input Box Restrictions
Description: This form validation JavaScript restricts the number of characters allowed inside an input field. Great for preventing people from overloading the form.
Example: Available
Copy the following code into your <HEAD></HEAD> tags.<!--Add other form elements into form as desired-->
<script>
<!--
/*
Visit http://java-scripts.net or http://wsabstract.com
For this script and more
*/
function checkchars(cur){
//change max length to determine below
var maxlength=50
if (cur.chars.value.length>maxlength){
alert("Please restrain your input to 50 or less characters!")
return false
}
}
//-->
</script>
Copy the following code between the <BODY></BODY> tags of your html page.<form onsubmit="return checkchars(this)">
<strong>In 50 chars or less, please type a short description of yourself:</strong><br><textarea rows="5" cols="38" name="chars"></textarea>
<br><input type="submit" value="Submit!">
</form>
Enter your name and email address to have this script sent right to your Inbox for later viewing.
© 2023 Javascripts
Now Viewing Input Box Restrictions