JavaScript forms and validation-non-null authentication _javascript Tips

Source: Internet
Author: User
Tags html form

Recommended reading: JavaScript form verification length

JavaScript Form validation-Submitting a form

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.

Check the legality of the data before submitting the form

When you want to verify the data in your form, you can use getElementById () to access any element on the page

Each form field has a Form object that can be passed to any function that validates the form's data

<input id= "ZipCode" name= "ZipCode" type= "text" size= "5" onclick= "Showit (this.form)"/>
function Showit ( Thisform)
{
alert (thisform["ZipCode"].value);
Gets the value of the element through the form object's Name property

Access to elements can be accomplished by using the Name property or the getElementById () method

The timing of checking the form data depends on selecting the correct user input event to process.

That is, the data is validated immediately after the user enters the data.

The order in which users enter data is:

Select input Field

Enter data in a field

Leave the field and move to the next target

Select the next target domain

Enter data in a field

In this process, a series of events are fired, using these events to find the time to validate the data

1 when the input field is selected – Fires the onfocus event (Focus)

2 when leaving the input field – fires the onblur event (leaving the focus)

3 Leave the field and the input content changes – fires the onchange event

The most correct choice is to validate the data when the onblur event is fired

First step of validation: Check that the domain is not empty

<input id= "Phone" name= "Phone" type= "text" size= "" Onblur= "Validatenonempty" (This) "/>

Call Validatenonempty to respond to onblur events

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

Here is the validation function

function Validatenonempty (Inputfield)
{
if (inputfield.value.length==0)
{
alert ("Please enter a Value. ");
return false;
} 
return true;
}

When the Web form is submitted, be sure to validate the data entered by the user

When you want to verify the data in your form, you can use getElementById () to access any element on the page

The above content is for JavaScript form and validation-not NULL verification of all the description, hope to help!

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.