JavaScript form Validation-Submitting Forms _javascript Tips

Source: Internet
Author: User
Tags html form

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.