Some common Javascript Form Verification Code

Source: Internet
Author: User

This article introduces some common Javascript Form Verification code, including email address, phone number, mobile phone number, ID card, website address, and so on.

The Code is as follows: Copy code
// Verify Email
Function checkEmail (mail ){
If (mail. length> 0 & mail. length <101 ){
Var regex =/^ [_. 0-9a-zA-Z +-] + @ ([0-9a-zA-Z] + [0-9a-zA-Z-] *.) + [a-zA-Z] {2, 4} $ /;
If (regex.exe c (mail )){
Return true;
}
}
Return false;
}
// Verify the zip code
Function checkZip (zip ){
Var regex =/^ [0-9] {6} $ /;
If (regex.exe c (zip )){
Return true;
}
Return false;
}
// Verify the ID card
Function checkIdCard (idcard ){
Var regex =/^ [0-9xX] {15,18} $ /;
If (regex.exe c (idcard )){
Return true;
}
Return false;
}
// Verify the fixed phone number
Function checkTel (tel ){
Var regex =/^ [0-9] {3, 4}-[0-9] {7, 8} $ /;
If (regex.exe c (tel )){
Return true;
}
Return false;
}
// Verify the mobile phone number
Function checkMobile (mobile ){
Var regex =/^ [0-9] {11} $ /;
If (regex.exe c (mobile )){
Return true;
}
Return false;
}
// Verify QQ
Function checkQQ (qq ){
Qq =$. trim (qq );
If (qq. length> 0 & qq. length <101 ){
Var regex =/^ [0-9] {1, 12} $ /;
If (regex.exe c (qq )){
Return true;
} Else {
Return checkEmail (qq );
}
}
Return false;
}
// Verify the name in Chinese, English or numbers
Function checkUname (name ){
Var regex =/^ [a-zA-Z0-9u4e00-u9fa5] {} $ /;
If (regex.exe c (name )){
Return true;
}
Return false;
}
Function checkUname (name, start, end ){
Var regex = new RegExp ("^ [a-zA-Z0-9 \ u4e00-\ u9fa5] {" + start + "," + end + "} $ ");
If (regex.exe c (name )){
Return true;
}
Return false;
}
// Verify the URL
Function checkSiteUrl (url ){
Var regex =/^ http: // ([a-zA-Z0-9] ([a-zA-Z0-9-] {} [a-zA-Z0-9])?.) + [A-zA-Z] {2, 6} (: [0-9] {1, 5 })? $ /;
If (regex.exe c (url )){
If (url. length: <201 ){
Var istrue = false;
$. Ajax ({
Type: "post ",
Url: "register. aspx ",
DataType: "html ",
Async: false,
Data: "url =" + escape (url) + "& t = checkUrl ",
Cache: false,
Success: function (data ){
If (data = "can "){
Istrue = true;
}
}
});
If (istrue ){
Return true;
}
}
}
Return false;
}

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.