hi every one
I put a textbox on my page and I want users to enter 11 digits in the textbox if they would enter less than 11 digits it will show an error
how I can do it?
best regards
Neda
Hi nedash,
Refer below sample.
HTML
<input name="txtDigits" type="text" id="txtDigits" onchange="Validate(this.value)" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" /> <span id="lblError" style="display: none; color: red">11 digits required.</span> <script type="text/javascript"> function Validate(value) { document.getElementById("lblError").style.display = value.length != 11 ? "block" : "none"; } var specialKeys = new Array(); specialKeys.push(8); function IsNumeric(e) { var keyCode = e.which ? e.which : e.keyCode var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1); return ret; } </script>
Demo
© COPYRIGHT 2024 ASPSnippets.com ALL RIGHTS RESERVED.