How To Restrict Entering A 9 Digit Number In Alpha Numeric Textbox
How to restrict user from entering a 9 digit number in alpha numeric textarea. the textarea can have alphabets. The textarea should allow all numbers except 9-digit numbers.
Solution 1:
What trigger do you use to validate the textbox? if is for submiting or a validate function, you can try
//regvalu can be ^[-+]?[1-9]\d*$(dont alow zero in from///or ^\d+$ for any digitvar regex = newRegExp(regVal)
if($('#textBox').length == 9 && regex.test($('#textBox').text())
{
alert('Your value is invalid');
}
Solution 2:
$('#txtName').keyup( function() {
var str = $(this).val();
var digits = str.replace(/\D/g, "##");
var splitdigits = digits.split("##");
if (splitdigits.length > 0)
{
for(varIcount = 0; Icount < splitdigits.length; Icount++)
{
if (splitdigits[Icount] != '' && splitdigits[Icount].match(/^\d+$/) && splitdigits[Icount].length == 9)
{
alert('Invalid input');
returnfalse;
}
}
}
});
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputid="txtName"type="text" >
Use above code in script tag u can change "#txtName" and use your textarea id
Post a Comment for "How To Restrict Entering A 9 Digit Number In Alpha Numeric Textbox"