文章来源:jquery教程 - http://www.jq-school.com/Show.aspx?id=310
.
一篇文章主要是收集了10个比较常用表单验证功能,包括了邮箱、危险字符、验证长度、验证网址、验证小数、整数、浮点数等常用的验证,有了这些代码片段,平时的表单验证也可以不需要jquery的验证插件了,希望可以帮到网友们。。。
71、原生ja
function isEmail(str){
var re=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
if (re.test(str) != true) {
return false;
}else{
return true;
}
}72、原生jafunction isValidReg(chars){
var re=/<|>|\[|\]|\{|\}|『|』|※|○|●|◎|§|△|▲|☆|★|◇|◆|□|▼|㊣|﹋|⊕|⊙|〒|ㄅ|ㄆ|ㄇ|ㄈ|ㄉ|ㄊ|ㄋ|ㄌ|ㄍ|ㄎ|ㄏ|ㄐ|ㄑ|ㄒ|ㄓ|ㄔ|ㄕ|ㄖ|ㄗ|ㄘ|ㄙ|ㄚ|ㄛ|ㄜ|ㄝ|ㄞ|ㄟ|ㄢ|ㄣ|ㄤ|ㄥ|ㄦ|ㄧ|ㄨ|ㄩ|■|▄|▆|\*|@|#|\^|\\/;
if (re.test( chars) == true) {
return false;
}else{
return true;
}
}73、原生jafunction isValidLength(chars, len) {
if (chars.length < len) {
return false;
}
return true;
}74、原生jafunction isValidURL( chars ) {
var re=/^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(\S+\.\S+)$/;
if (!isNULL(chars)) {
chars = jsTrim(chars);
if (chars.match(re) == null)
return false;
else
return true;
}
return false;
}75、原生jafunction isValidDecimal( chars ) {
var re=/^\d*\.?\d{1,2}$/;
if (chars.match(re) == null)
return false;
else
return true;
}76、原生jafunction isNumber( chars ) {
var re=/^\d*$/;
if (chars.match(re) == null)
return false;
else
return true;
}77、原生jafunction isFloat( str ) {
for(i=0;i<str.length;i++) {
if ((str.charAt(i)<"0" || str.charAt(i)>"9")&& str.charAt(i) != '.'){
return false;
}
}
return true;
}78、原生jafunction isLetters( str ){
var re=/^[A-Za-z]+$/;
if (str.match(re) == null)
return false;
else
return true;
}79、原生jafunction isValidPost( chars ) {
var re=/^\d{6}$/;
if (chars.match(re) == null)
return false;
else
return true;
}80、原生jafunction isNULL( chars ) {
if (chars == null)
return true;
if (jsTrim(chars).length==0)
return true;
return false;
} 最佳答案