Checking string length
Sometimes situation arises when a field in an html form accept a restricted number of characters. For example a userid (length between 6 to 10 character) or password (length between 8 to 14 characters). You can write a JavaScript form validation script where the required field(s) in the HTML form accepts the restricted number of characters.
Javascript function to restrict length of user input
Flowchart:

Here's an example of the above function for a field that requires 6 to 8 characters to valid a usercode.
HTML Code
Javascript code
CSS Code
Practice the example online
No comments:
Post a Comment