Internet
Fact-checked

At EasyTechJunkie, we're committed to delivering accurate, trustworthy information. Our expert-authored content is rigorously fact-checked and sourced from credible authorities. Discover how we uphold the highest standards in providing you with reliable knowledge.

Learn more...

What is JavaScript® Form Validation?

Vanessa Harvey
Vanessa Harvey

JavaScript® form validation refers to the use of the JavaScript® language to write scripts that help ensure that the information that visitors to a website enter into the form fields of a form is valid before it is processed. For example, no email address can be considered valid if it lacks the "@" symbol, and all types of valid telephone numbers are more than one digit. Front-end and back-end web developers frequently handle JavaScript® form validation to legitimately collect and process information from website visitors for a number of purposes, such as receiving email through a contact form. Minimum data that needs to be gathered include the visitor's name, email address and message so that the webmaster or person to whom the email is directed knows who made the contact, to what email address he or she should respond and the content of the visitor's message.

Typical information for which a web developer might do JavaScript® form validation include checking the length of a password; comparing the confirmation password to the proposed password; and checking the prefix, length and expiration date of a credit card. Depending on the purpose and type of the information that is being requested of the visitor, JavaScript® form validation might also be used to verify that all required form fields not only contain data that looks valid, but that the field is not left empty. Making sure that information is not missing can be just as important as testing it for validity. Although JavaScript® does a good job of verifying information to see whether it appears to be valid, the fact is that this is the only thing it can do. This is why online forms must be filled out accurately by the visitor.

JavaScript form validation might be used to check a credit card's expiration date and other information.
JavaScript form validation might be used to check a credit card's expiration date and other information.

If a mistake is made in typing one character of an email address or in one digit of a phone number, the script will see the information as valid as long as the format in which it is entered appears to be valid. Millions of websites rely on JavaScript® form validation, which attests to the efficacy of the many well-written scripts that have been coded in this language for client-side validation of user data. This does not mean, however, that there are no disadvantages to validation or at least to using it as the only way of checking information that website visitors enter into form fields. Support for JavaScript® can be turned on and off by the operator of the client computer by modifying configuration settings within the web browser.

JavaScript® support is almost always on by default, and the average person is unaware of how to turn it off in his or her browser or even that it can be turned off. If, however, support for the language is turned off, scripts of any kind written in the language cannot run, allowing invalid information to be processed. Some websites alert visitors of the need to enable JavaScript® if it is turned off.

Discuss this Article

Post your comments
Login:
Forgot password?
Register:
    • JavaScript form validation might be used to check a credit card's expiration date and other information.
      By: Chad McDermott
      JavaScript form validation might be used to check a credit card's expiration date and other information.