Html code for validating username and password

If the colors ever need to be changed, they can easily be changed in one place.

Check the Values Comparing the values of the pass1 and pass2 objects will tell us whether or not the password is the same.

This will allow us to change other properties of the object later on.

Now that you have the basic knowledge, you can experiment with it and add new features, such as a “Forgot password” page to allow the user to retrieve or change his password if he forgets it. You can freely use it on commercial or non-commercial websites.

9th Jan 2012 Reset Password/Change Password features are added.

If its not blank, we check the length of the string and permit only usernames that are between 5 and 15 characters.

Next, we use the Java Script regular expression /\W/ to forbid illegal characters from appearing in usernames.

For the majority of your users, Java Script form validation will save a lot of time up front, but double-checking the data on the server remains necessary, in case the user has turned Java Script off.

Form data that typically are checked by a Java Script could be: validate Form On Submit ( ) This is a main function that calls a series of subfunctions, each of which checks a single form element for compliance.If the element complies than sufunction returns an empty string.Otherwise it returns a message describing the error and highlight appropriate element with yellow.Extending the Script Changing the colors is a great visual identifier for the user, but for added security, the script could be extended to disable the form submit button or alert the user before they submit the form if the passwords do not match.The script and form could also be changed to use images for the confirmation rather than text.Notice that we are setting an “authorized” session variable in the login code above.