Detailed JavaScript form verification (e-mail verification) _javascript Tips

Source: Internet
Author: User
Tags html form

This article has shared JavaScript form validation, and these typical form data validated by JavaScript are:
Has the user filled out the required items in the form?
is the e-mail address that the user entered legal?
Has the user entered a valid date?
Does the user enter text in the Data field (numeric field)?
Required (or required) items
The following function is used to check whether the user has filled in the required (or required) items in the form. If a required or required option is blank, the warning box pops up and the function's return value is false, otherwise the function's return value is true (meaning there is no problem with the data):

function validate_required (field,alerttxt)
{with
(field)
{
if value==null| | value== "")
 {alert (alerttxt); return false}
else {return true}
}
}

Here's the code for the HTML form:

 
 

E-mail verification
The following function checks whether the data entered conforms to the basic syntax of the e-mail address.
This means that the data you enter must contain the @ symbol and the point number (.). At the same time, @ can not be the first character of the mail address, and after @ must have at least one point number:

function Validate_email (field,alerttxt)
{with
(field)
{
apos=value.indexof ("@")
dotpos= Value.lastindexof (".")
if (apos<1| | DOTPOS-APOS<2) 
 {alert (alerttxt); return false} '
else {return true}}
}

Here is the complete code for the HTML form:

 
 

The above is the entire content of this article, I hope that you learn JavaScript form validation help.

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.