Home > Web Front-end > JS Tutorial > body text

Detailed introduction to the format of JS regular verification email_javascript skills

WBOY
Release: 2016-05-16 17:14:17
Original
1065 people have browsed it

For those of us doing WEB development, form verification is essential, so today I will list some commonly used verifications. Haha, I just learned the JS regular expressions this afternoon. I hope you have any shortcomings. Criticize and correct.

1. Relevant code

Copy code The code is as follows:

function test()
{
var temp = document.getElementById("text1");
//Verification of email
var myreg = /^([a-zA-Z0 -9] [_|/_|/.]?)*[a-zA-Z0-9] @([a-zA-Z0-9] [_|/_|/.]?)*[a- zA-Z0-9] /.[a-zA-Z]{2,3}$/;
if(!myreg.test(temp.value))
{
alert('hint/ n/nPlease enter a valid E_mail! ');
myreg.focus();
return false;
}
}
//Since the method is the same, only the relevant ones will be written here Regular expression
//Verification of mobile phone number (two methods are provided)
var mobile=/^((13[0-9]{1})|159|153) /d{8} $/;
var mobile1=/^(13 /d{9})|(159 /d{8})|(153 /d{8})$/;
//Verification of area code
var phoneAreaNum = /^/d{3,4}$/;
//Verification of phone number
var phone =/^/d{7,8}$/;
}

2. Explain the relevant meanings
1. /^$/ This is a general format.
^ matches the start position of the input string; $ matches the end position of the input string

2. Enter the function to be implemented.
* Matches the previous subexpression zero or more times;
Matches the previous subexpression one or more times;
? Matches the previous subexpression zero or once;
/d matches a numeric character, equivalent to [0-9]
Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!