📄 check.js
字号:
return false;
}
ele.value=elevalue;
if (ele.maxValue)
{
return(checkMaxValue(ele));
}
if (ele.minValue)
{
return(checkMinValue(ele));
}
return true;
}
function checkString(ele)
{
//暂时规定字符串内不能包含单引号以及双引号,如果找到了清空此输入框
if (ele.value.indexOf("'")!=-1)
{
bCheckLock = false;
alert("不能包含单引号");
return false;
}
if (ele.value.indexOf("\"")!=-1)
{
bCheckLock = false;
alert("不能包含单引号");
return false;
}
var regobj = /\s+$/g;
var s_end = (ele.value).replace(regobj,'');
var regobjb = /^\s+/g;
ele.value = (s_end).replace(regobjb,'');
return true;
}
function checkLongString(ele)
{
//暂时规定长字符串内不能包含单引号以及双引号,如果找到了,去处这些单引号和双引号
if (ele.value.indexOf("'") != -1)
{
alert("不能包含单引号");
return false;
}
if (ele.value.indexOf("\"") != -1)
{
alert("不能包含单引号");
return false;
}
if (ele.maxl) {
if (ele.value.length>ele.maxl)
{
alert("最长不能超过" + ele.maxl+"个字!");
return false;
}
}
var regobj = /\s+$/g;
var s_end = (ele.value).replace(regobj,'');
var regobjb = /^\s+/g;
ele.value = (s_end).replace(regobjb,'');
return true;
}
function checkPost(ele)
{
if (ele.value.length != 6)
{
bCheckLock = false;
alert("邮编格式错误!\n正确的格式: 710043");
return false;
}
var num = new Number(ele.value);
if (isNaN(num))
{
bCheckLock = false;
alert("邮编格式错误!\n正确的格式: 710043");
return false;
}
if (num < 0)
{
bCheckLock = false;
alert("邮编格式错误!\n正确的格式: 710043");
return false;
}
if (ele.value.indexOf(".")!=-1)
{
bCheckLock = false;
alert("邮编格式错误!\n正确的格式: 710043");
return false;
}
return true;
}
function checkPhone(ele)
{
var ev = ele.value;
//检测长度是否足够
if (ev.length<7)
{
bCheckLock = false;
alert("电话号码格式错误!\n正确的格式: 029-84111130");
return false;
}
//检测长度是否超过限制
if (ev.length>20)
{
bCheckLock = false;
alert("电话号码格式错误!\n正确的格式: 029-84111130");
return false;
}
//检测是否含有非法字符
if ( (ev.indexOf("'")!=-1)||(ev.indexOf("\"")!=-1))
{
bCheckLock = false;
alert("电话号码格式错误!\n正确的格式: 029-84111130");
return false;
}
//允许出现两次"("号,两次")"号,两次"-"号,一次","号,一次";"号
//其余的必须为数字
var re = "(";
var sTemp = ev.replace( re, "" );
re =")";
sTemp = sTemp.replace( re, "" );
re = "-";
sTemp = sTemp.replace( re, "" );
re = "(";
var sTemp = ev.replace( re, "" );
re =")";
sTemp = sTemp.replace( re, "" );
re = "-";
sTemp = sTemp.replace( re, "" );
re = ",";
sTemp = sTemp.replace( re, "" );
re = ";";
sTemp = sTemp.replace( re, "" );
var elevalue = new Number(sTemp);
if ( isNaN(elevalue) )
{
bCheckLock = false;
alert("电话号码格式错误!\n正确的格式: 029-84111130");
return false;
}
return true;
}
function checkMobilephone(ele)
{
if (ele.value.length !== 11)
{
alert("手机号码应为11位!");
return false;
}
var elevalue = new Number(ele.value);
if ( isNaN(elevalue) )
{
alert("手机号码必须是数字!");
return false;
}
if (ele.value.substring(0,2) != '13')
{
alert("输入的不是手机号码");
return false;
}
return true;
}
function checkIP (ele)
{
var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
var ipArray = ele.value.match(ipPattern);
if (ipArray == null) {
alert("格式:192.168.0.1");
return false;
}
else {
var i;
for (i = 1; i <= 4; i++) {
var thisSegment = ipArray[i];
if (thisSegment > 255) {
alert("格式:192.168.0.1");
return false;
}
}
}
return true;
}
function checkMask(ele)
{
var knownMasksPat1=/^(0.0.0.0|128.0.0.0|192.0.0.0|224.0.0.0|240.0.0.0|248.0.0.0|252.0.0.0|254.0.0.0|255.0.0.0)$/;
var knownMasksPat2=/^(255.128.0.0|255.192.0.0|255.224.0.0|255.240.0.0|255.248.0.0|255.252.0.0|255.254.0.0|255.255.0.0)$/;
var knownMasksPat3=/^(255.255.128.0|255.255.192.0|255.255.224.0|255.255.240.0|255.255.248.0|255.255.252.0|255.255.254.0|255.255.255.0)$/;
var knownMasksPat4=/^(255.255.255.128|255.255.255.192|255.255.255.224|255.255.255.240|255.255.255.248|255.255.255.252|255.255.255.254|255.255.255.255)$/;
if (ele.value.search(knownMasksPat1) < 0 &&
ele.value.search(knownMasksPat2) < 0 &&
ele.value.search(knownMasksPat3) < 0 &&
ele.value.search(knownMasksPat4) < 0) {
alert("错误的掩码格式");
return false;
}
return true;
}
function oldcheckEmail(ele)
{
var index = ele.value.indexOf("@");
if (index < 0)
{
alert("错误的Email格式");
return false;
}
if (ele.value.indexOf("@",index+1) != -1)
{
alert( "错误的Email格式");
return false;
}
if (ele.value.length < 6 )
{
alert( "错误的Email格式");
return false;
}
var iDot;
var sTail;
iDot = ele.value.lastIndexOf(".");
sTail = ele.value.substring(iDot, ele.value.length);
sTail = sTail.toLowerCase();
if (!(sTail == ".cn" || sTail == ".com" || sTail == ".net" || sTail == ".org" || sTail == ".edu"))
{
alert( "错误的Email格式");
return false;
}
return true;
}
function checkDomainInternal (domain)
{
/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD. 1 means check it, 0 means don't. */
var checkTLD=1;
/* The following is the list of known TLDs that an e-mail address must end with. */
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
/* The following string represents the pattern for matching all special
characters. We don't want to allow special characters in the address.
These characters include ( ) < > @ , ; : \ " . [ ] */
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
/* The following string represents the range of characters allowed in a
username or domainname. It really states which chars aren't allowed.*/
var validChars="\[^\\s" + specialChars + "\]";
/* The following string represents an atom (basically a series of non-special characters.) */
var atom=validChars + '+';
/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")";
/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
/* Finally, let's start trying to figure out if the supplied address is valid. */
// Start by checking that only basic ASCII characters are in the strings (0-127).
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("错误的域名格式");
return false;
}
}
// Domain is symbolic name. Check if it's valid.
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("错误的域名格式");
return false;
}
}
/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding
the domain or country. */
if (checkTLD && domArr[domArr.length-1].length!=2 &&
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("错误的域名格式");
return false;
}
// Make sure there's a host name preceding the domain.
if (len<2) {
alert("错误的域名格式");
return false;
}
// If we've gotten this far, everything's valid!
return true;
}
function checkDomain (ele)
{
return checkDomainInternal(ele.value);
}
function checkAnyDomain (ele)
{
var absDomPat=/^(\w+).$/;
var domArray = ele.value.match(absDomPat);
if (domArray == null)
return checkDomainInternal(ele.value);
else
return checkDomainInternal(domArray[0]);
}
function checkAbsDomain (ele)
{
var absDomPat=/^(\w+).$/;
var domArray = ele.value.match(absDomPat);
if (domArray == null) {
alert("错误的Email格式");
return false;
}
return checkDomainInternal(domArray[0]);
}
function checkEmail (ele)
{
/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD. 1 means check it, 0 means don't. */
var checkTLD=1;
/* The following is the list of known TLDs that an e-mail address must end with. */
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
/* The following pattern is used to check if the entered e-mail address
fits the user@domain format. It also is used to separate the username
from the domain. */
var emailPat=/^(.+)@(.+)$/;
/* The following string represents the pattern for matching all special
characters. We don't want to allow special characters in the address.
These characters include ( ) < > @ , ; : \ " . [ ] */
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
/* The following string represents the range of characters allowed in a
username or domainname. It really states which chars aren't allowed.*/
var validChars="\[^\\s" + specialChars + "\]";
/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes). E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")";
/* The following pattern applies for domains that are IP addresses,
rather than symbolic names. E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
/* The following string represents an atom (basically a series of non-special characters.) */
var atom=validChars + '+';
/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")";
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
/* Finally, let's start trying to figure out if the supplied address is valid. */
/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */
var matchArray=ele.value.match(emailPat);
if (matchArray==null) {
/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */
alert("错误的Email格式");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
// Start by checking that only basic ASCII characters are in the strings (0-127).
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("错误的Email格式");
return false;
}
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("错误的Email格式");
return false;
}
}
// See if "user" is valid
if (user.match(userPat)==null) {
// user is not valid
alert("错误的Email格式");
return false;
}
/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
// this is an IP address
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("错误的Email格式");
return false;
}
}
return true;
}
// Domain is symbolic name. Check if it's valid.
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("错误的Email格式");
return false;
}
}
/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding
the domain or country. */
if (checkTLD && domArr[domArr.length-1].length!=2 &&
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("错误的Email格式");
return false;
}
// Make sure there's a host name preceding the domain.
if (len<2) {
alert("错误的Email格式");
return false;
}
// If we've gotten this far, everything's valid!
return true;
}
function CheckAll(eles)
{
var i;
for (i=0;i<eles.length;i++) {
if (!checkValidate(eles[i]))
return false;
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -