Some common JavaScript form validation code

Source: Internet
Author: User
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.exec (mail)) {
return true;
}
}
return false;
}
Verify ZIP Code
function Checkzip (Zip) {
var regex =/^[0-9]{6}$/;
if (regex.exec (Zip)) {
return true;
}
return false;
}
Verify ID
function Checkidcard (idcard) {
var regex =/^[0-9xx]{15,18}$/;
if (Regex.exec (Idcard)) {
return true;
}
return false;
}
Verify fixed
function Checktel (tel) {
var regex =/^[0-9]{3,4}-[0-9]{7,8}$/;
if (regex.exec (tel)) {
return true;
}
return false;
}
Verify the phone
function Checkmobile (MOBILE) {
var regex =/^[0-9]{11}$/;
if (Regex.exec (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.exec (QQ)) {
return true;
} else {
Return Checkemail (QQ);
}
}
return false;
}
Verification name Chinese, English or digital
function Checkuname (name) {
var regex =/^[a-za-z0-9u4e00-u9fa5]{2,10}$/;
if (regex.exec (name)) {
return true;
}
return false;
}
function Checkuname (name,start,end) {
var regex = new RegExp ("^[a-za-z0-9\u4e00-\u9fa5]{" +start+ "," +end+ "}$");
if (regex.exec (name)) {
return true;
}
return false;
}
Verify URL
function Checksiteurl (URL) {
var regex =/^http://([a-za-z0-9] ([a-za-z0-9-]{0,61}[a-za-z0-9])? +[a-za-z]{2,6} (: [0-9]{1,5})? $/;
if (regex.exec (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;
}
Related Article

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.