Javascript form and verification-non-empty verification, javascript form

Source: Internet
Author: User

Javascript form and verification-non-empty verification, javascript form

Recommended: Javascript Form Verification Length

Javascript form verification-submit a form

Form Verification in Javascript-Regular Expressions first recognized

Javascript form verification-uncover the veil of Regular Expressions

JavaScript can be used to verify the input data in the HTML form before the data is sent to the server.

Check the validity of the data before submitting the form.

To verify the data in the form, you can use getElementById () to access any element on the webpage.

Each form field has a form object that can be passed to any function that verifies form data.

<Input id = "zipcode" name = "zipcode" type = "text" size = "5" onclick = "showIt (this. form) "/> function showIt (thisForm) {alert (thisForm [" zipcode "]. value); // obtain the element value through the name attribute of the form object}

You can use the name attribute or the getElementById () method to obtain the element.

The time to check the form data depends on selecting the correct user input event for processing.

That is, data is verified immediately after the user inputs the data.

The order of user input data is as follows:

Select input field

Input data in the domain

Leave the domain and move down the target

Select the next target domain

Input data in the domain

In this process, a series of events will be triggered. With these events, you can find the time to verify the data.

1) when the input domain is selected, the onfocus event is triggered)

2) When leaving the input domain-fires the onblur event (leave Focus)

3) when the domain is left and the input content changes, the onchange event is triggered.

The most correct choice is to verify the data when an onblur event is triggered.

Step 1 of verification: Check that the domain is not empty

<input id="phone" name="phone" type="text" size="12" onblur="validateNonEmpty(this)"/>

Call validateNonEmpty to respond to the onblur event

The form object uses the keyword "this" to be passed to the function.

The following are the verification functions:

function validateNonEmpty(inputField){if(inputField.value.length==0){alert("Please enter a value.");return false;} return true;}

When submitting a webpage form, you must verify the data entered by the user.

To verify the data in the form, you can use getElementById () to access any element on the webpage.

The above content is a full description of the Javascript form and verification-non-empty verification, I hope to help you!

Articles you may be interested in:
  • Simple js form verification functions
  • Js uses regular expressions to verify the form (relatively complete resources)
  • Javascript Form Verification example (javascript verification email)
  • Extjs form common verification Summary
  • AngularJS implements Form Verification
  • Jquery Form Verification plug-in (jquery. validate. js)
  • Form Verification of simple registration module made by javascript

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.