相思资源网 Design By www.200059.com
复制代码 代码如下:
//字符处理;
//去左右空格;
function trim(s){
return rtrim(ltrim(s));
}
//去左空格;
function ltrim(s){
return s.replace( /^\s*/, "");
}
//去右空格;
function rtrim(s){
return s.replace( /\s*$/, "");
}
//验证信息;
//空字符值;
function isEmpty(s){
s = trim(s);
return s.length == 0;
}
//Email;
function isEmail(s){
s = trim(s);
var p = /^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.){1,4}[a-z]{2,3}$/i;
return p.test(s);
}
//数字;
function isNumber(s){
return !isNaN(s);
}
//颜色值;
function isColor(s){
s = trim(s);
if (s.length !=7) return false;
return s.search(/\#[a-fA-F0-9]{6}/) != -1;
}
//手机号码;
function isMobile(s){
s = trim(s);
var p = /13\d{9}/;
return p.test(s);
}
//身份证;
function isCard(s){
s = trim(s);
var p = /^\d{15}(\d{2}[xX0-9])?$/;
return p.test(s);
}
//URL;
function isURL(s){
s = trim(s).toLowerCase();
var p = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
return p.test(s);
}
//Phone;
function isPhone(s){
s = trim(s);
var p = /^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/;
return p.test(s);
}
//Zip;
function isZip(s){
s = trim(s);
var p = /^[1-9]\d{5}$/;
return p.test(s);
}
//Double;
function isDouble(s){
s = trim(s);
var p = /^[-\+]?\d+(\.\d+)?$/;
return p.test(s);
}
//Integer;
function isInteger(s){
s = trim(s);
var p = /^[-\+]?\d+$/;
return p.test(s);
}
//English;
function isEnglish(s){
s = trim(s);
var p = /^[A-Za-z]+$/;
return p.test(s);
}
//中文;
function isChinese(s){
s = trim(s);
var p = /^[\u0391-\uFFE5]+$/;
return p.test(s);
}
//双字节
function isDoubleChar(s){
var p = /^[^\x00-\xff]+$/;
return p.test(s);
}
//含有中文字符
function hasChineseChar(s){
var p = /[^\x00-\xff]/;
return p.test(s);
}
function hasAccountChar(s){
var p = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,15}$/;
return p.test(s);
}
function limitLen(s,Min,Max){
s=trim(s);
if(s=="") return false;
if((s.length<Min)||(s.length>Max))
return false;
else
return true;
}
//字符处理;
//去左右空格;
function trim(s){
return rtrim(ltrim(s));
}
//去左空格;
function ltrim(s){
return s.replace( /^\s*/, "");
}
//去右空格;
function rtrim(s){
return s.replace( /\s*$/, "");
}
//验证信息;
//空字符值;
function isEmpty(s){
s = trim(s);
return s.length == 0;
}
//Email;
function isEmail(s){
s = trim(s);
var p = /^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.){1,4}[a-z]{2,3}$/i;
return p.test(s);
}
//数字;
function isNumber(s){
return !isNaN(s);
}
//颜色值;
function isColor(s){
s = trim(s);
if (s.length !=7) return false;
return s.search(/\#[a-fA-F0-9]{6}/) != -1;
}
//手机号码;
function isMobile(s){
s = trim(s);
var p = /13\d{9}/;
return p.test(s);
}
//身份证;
function isCard(s){
s = trim(s);
var p = /^\d{15}(\d{2}[xX0-9])?$/;
return p.test(s);
}
//URL;
function isURL(s){
s = trim(s).toLowerCase();
var p = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
return p.test(s);
}
//Phone;
function isPhone(s){
s = trim(s);
var p = /^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/;
return p.test(s);
}
//Zip;
function isZip(s){
s = trim(s);
var p = /^[1-9]\d{5}$/;
return p.test(s);
}
//Double;
function isDouble(s){
s = trim(s);
var p = /^[-\+]?\d+(\.\d+)?$/;
return p.test(s);
}
//Integer;
function isInteger(s){
s = trim(s);
var p = /^[-\+]?\d+$/;
return p.test(s);
}
//English;
function isEnglish(s){
s = trim(s);
var p = /^[A-Za-z]+$/;
return p.test(s);
}
//中文;
function isChinese(s){
s = trim(s);
var p = /^[\u0391-\uFFE5]+$/;
return p.test(s);
}
//双字节
function isDoubleChar(s){
var p = /^[^\x00-\xff]+$/;
return p.test(s);
}
//含有中文字符
function hasChineseChar(s){
var p = /[^\x00-\xff]/;
return p.test(s);
}
function hasAccountChar(s){
var p = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,15}$/;
return p.test(s);
}
function limitLen(s,Min,Max){
s=trim(s);
if(s=="") return false;
if((s.length<Min)||(s.length>Max))
return false;
else
return true;
}
标签:
js,验证函数
相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com
暂无js一组验证函数的评论...