Validating User Input string length in a text box.
In this article we will see how we can validate or limit the length of the user input string.
One way is sitting the max length property of the textbox, but that will only validate the max no of characters that can be entered in the textbox. But what is we need to do a validation like the password should be minimum of 6 characters in length and should not exceed 15 characters.
Is it possible, yes it is, we can use java script to validate this. The following is the script.
[code]
function checkCharLen()
{
if (form1.text1.value.length >=6 && form1.text1.value.length <=15)
{ return true; }
else
{ alert(“Should be 6 to 15 characters”);
form1.text1.focus(); return false;
}
}
[/code]
We need to call this function in the OnBlur event of the textbox. OnBlur event will fire when the focus is lost.
