Function for verifying email addresses using JavaScript, and javascript email address

Source: Internet
Author: User

Function for verifying email addresses using JavaScript, and javascript email address

This article introduces a function for verifying email addresses using JavaScript, which is quite reliable.

The function for verifying email addresses using JavaScript. The source code is as follows:

function checkEmail(text) { if( text.match(/qq\.com$/) ) {  return -1; } if( ! text.match(/^\w+([._-]\w+)*@(\w+\.)+\w+$/) ) {  return false; } return true;}

This article introduces so many functions for verifying email addresses using JavaScript. Thank you!


Javascript email verification problems

Regular Expressions can be used to solve the problem. However, it is easier to divide the mailbox into three input boxes.
The middle @ and. are fixed

Regular:/^ ([\ w-\.] +) @ (\ [0-9] {1, 3 }\. [0-9] {1, 3 }\. [0-9] {1, 3 }\.) | ([\ w-] + \.) +) ([a-zA-Z] {2, 4} | [0-9] {1, 3}) (\]?) $/. Test (mail. value)

Use JavaScript to write a function checkForm () to verify whether the email address is correct

Function f_checkMail (){
Var email = document. myform. email. value;

// @ Symbol exists
Var a = email. indexOf ("@");

// Existence point
Var point = email. indexOf (".");

// @ Exists, points, and points are not adjacent after @
If (a =-1 | point =-1 | point-a <= 1 ){
Alert ("the email format is incorrect. Correct like abc@163.com ");
Document.myForm.txt Mail. select ();
Return false;
}

// @ Cannot be the first character, and the vertex cannot be the last character
If (a = 0 | point = email. length-1 ){
Alert ("the email format is incorrect. Correct like abc@163.com ");
Document.myForm.txt Mail. select ();
Return false;
}

Return true;
}

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.