JavaScript can be used to verify the input data in the HTML form before the data is sent to the server. This article introduces the length of Javascript form verification. For more information, see JavaScript to verify the input data in the HTML form before the data is sent to the server.
What method should we use to remind users? You do not want to use the alert () Prompt box
Add an sqan label after the input field
Function validate_Length (inputFiled, helpText) {// if the content of the input field is null, the if (inputFiled. value. length = 0) {if (helpText! = Null) helpText. innerHTML = "text box cannot be blank";} // if the input field is not empty, the else if (helpText! = Null) helpText. innerHTML = ""} script
HelpText is the input span object.
The span label is used to remind users. It does not block user vision as alert does.
Besides non-empty verification, there are also dimensional problems
Verify Data Length
Here the parameter is changed to four, the first is the minimum length of the text, and the second is the maximum length of the text.
Function validate_Length (minleworkflow, maxlength, inputFiled, helpText) {if (inputFiled. value. length
Maxlength) {if (helpText! = Null) {helpText. innerHTML = "Enter the length of" + minLenght + "to" + maxLength + "text"; return false ;}} else if (helpText! = Null) {helpText. innerHTML = "" return true ;}}
Verify zip code
Function validate_ZipCode (inputFiled, helpText) {if (inputFiled. value. length! = 5) {if (helpText! = Null) helpText. innerHTML = "the zip code must be 5 characters long"; return false;} else if (isNaN (inputFiled. value) {if (helpText! = Null) helpText. innerHTML = "the zip code must be a number"; return false;} else if (helpText! = Null) {helpText. innerHTML = "" return true ;}}