JavaScript form Validation-Mailbox verification

Source: Internet
Author: User

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>Title</title>
<script type= "Text/javascript" >
function Validate_email (field,text) {
With (field) {
With is similar to C + + namespace, simply say is the name space, that is, with the {} There is no need to write thisform.xxx, directly write XXX means that is thisform
Here's Value=field.value
apos = value.indexof ("@");//Get where "@" appears
Dotpos = Value.lastindexof ("."); /get "." The location that appears
if (apos<1| | DOTPOS-APOS&LT;2) {//To make a judgment, enter the mailbox must contain the "@" symbol and the dot number "." At the same time "@" can not be the first character of the email address, and "@" must have at least one "." No.
alert (text);//If the condition is true, the cue box pops up
Return false;//here returns false, which means a serious failure
}else{
Alert ("submit succeeded \ n \ nthe Click OK to continue")//if the condition is not set, the Prompt box pops up
Return true;//means validation is successful
}
}
}
function Validate_form (thisform) {//Because onsubmit calls Validate_form (this), here is the form itself, Thisform received this form can also be changed into a form
With (Thisform) {
With is similar to C + + namespace, simply say is the name space, that is, with the {} There is no need to write thisform.xxx, directly write XXX means that is thisform
Here in the Email=thisform.email=form Name=email
if (validate_email (email, "Please enter the correct email address") ==false) {//Call the validate_required parameter is a reference to the name=email tag below Thisform, and the other argument is a string
Email.focus ();//If Validate_email returns FALSE, the focus is set to the email
Return false;//here returns false, which means the validation fails and the form is not committed
}
}
}
</script>

<body>
<form action= "javascript:;" onsubmit= "return Validate_form (This)" method= "POST" ><!--when the form is submitted, the Validate_ is executed first Form (). parameter is the form itself this-->
Email: <input type= "text" id= "email" name= "email" size= "/>"
<input type= "Submit" value= "submitted" id= "Submission"/>
</form>
</body>

JavaScript form Validation-Mailbox verification

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.