JavaScript phone, QQ, mobile phone, ID number, email address, post regular expression validation code

Source: Internet
Author: User
Tags regular expression

JavaScript Tutorials Phone, QQ, mobile phone, ID number, email address, post regular expression validation code
< Head>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312"/>
<title> JavaScript phone, QQ, mobile phone, ID number, email address, post regular expression validation code </TITLE>
<script language= "javascript"
function $ (ID)
{
 return document.getElementById (ID);
}
Function Checkidcard (idcard) {
 idcard = trim (idcard);
 len = Mb_strlen (Idcard);
 if (len = && Preg_match (/^d{17}[dx]$/i, Idcard)) {
  return true;
 }
 return Dalert ( ' ID number is illegal! Please re-fill ', $ (' Form1 '). Idcard);
}

function Checktel (Tel1, Tel2, Tel3, Telname) {
if (!preg_match (/^d{2,4}$/, tel1) | | |!preg_match (/^d{5,10}$/, tel2) | | (Tel3 && tel3!= ' extension number ' &&!preg_match (/^d{1,5}$/, TEL3))) {
Return Dalert (telname + ' illegal!) Please re-fill ', $ (' Form1 '). Tel1);
}
return true;
}

function Checkqq (QQ) {
if (!) ( Preg_match (/^ ([0-9]+) $/, QQ) && Mb_strlen (QQ) >= 5 && Mb_strlen (QQ) <= 12)) {
Return Dalert (' QQ number is not legal! Please re-fill ', $ (' Form1 '). QQ);
}
return true;
}

function Checkmobile (MOBILE) {
if (!preg_match (/^1 (3|5) d{9}$/, mobile)) {
Return Dalert (' mobile number is not legal! Please re-fill ', $ (' Form1 '). Mobile);
}
return true;
}

function Checkpostcode (postcode) {
if (!preg_match (/^d{6}$/, postcode)) {
return Dalert (' ZIP code not valid! Please re-fill ', $ (' Form1 '). Postcode);
}
return true;
}
</script>

<body>
</body>

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.