Recommended reading: JavaScript form verification length
JavaScript form Validation-the first recognition of regular expressions
JavaScript form Validation-uncovering the veil of the regular expression
JavaScript can be used to validate these input data in an HTML form before the data is sent to the server.
Bad data should not arrive at the server: validation when submitting a form
There is a form attribute in the form Field object that uses an array to represent the entire form's fields
If there is only a simple information text box and a ZIP code box, there is also a submit button
<form> <input id= "message" name= "message" type= "text" size= "" onblur= "Validate_length (1,32,this, document.getElementById (' message_help ')); "/> <message_help" class= "Help" ></span> <input id= " ZipCode "name=" Phone "type=" text "size=" 5 "onblur=" Validate_zipcode (This,document.getelementbyid (' zipcode_help ')); " /> <span id= "zipcode_help" class= "Help" ></span> <input type= "button" value= "Order Banner" onclick= " PlaceOrder (This.form); " /> </form> <script language= "javascript" type= "Text/javascript" >//Text length validation function validate_length ( Minlegth,maxlength,inputfiled,helptext) {if (inputfiled.value.length<minlegth| | Inputfiled.value.length>maxlength) {if (helptext!=null) {helptext.innerhtml= "Please enter a length of" +minlenght+ "to" +maxLength+ "
's text ";
return false;
} else if (helptext!=null) {helptext.innerhtml= "" return True;}}
Zip Code validation function Validate_zipcode (inputfiled,helptext) {if (inputfiled.value.length!=5) {if (helptext!=null) Helptext.innerhtMl= "The postal code length must be 5 digits";
return false; else if (isNaN (Inputfiled.value)) {if (helptext!=null) helptext.innerhtml= "Postal code must be number"; return false;} else if (HelpText
!=null) {helptext.innerhtml= "" return True;}} function PlaceOrder (form) {if (Validatenonempty (1,32,form["Phone"],form["Phone_help"]) &&validate_zipcode (
form["ZipCode"],form["Zipcode_help")) {Form.submit ();} else{alert ("You have completed at least one illegal form data");} </script>
Summary: Just call the appropriate validation function, get the return value, you can complete the final submission of the form when the final data filter
In practical application, often need to the length of data, non-empty, illegal characters, format, size and so on to do validation, here not a description, emphasis on understanding.
Ok, about JavaScript form validation-submit the form of knowledge, small part of the introduction to everyone here, I hope to help you!