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>