加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式,先保留一份正确的、全的

发布时间:2020-12-14 04:35:02 所属栏目:百科 来源:网络整理
导读://使用示例//商品售价if($('#productPrice').val()!=null){if(!(/^d+(.d+)?$/i.test($('#productPrice').val()))){alert("失败啦");returnfalse;}else{alert("是数字");}}/***扩展的基本校验规则,*/$.extend($.fn.validatebox.defaults.rules,{minLength
//使用示例
//商品售价
	if($('#productPrice').val()!=null){
		if(!(/^d+(.d+)?$/i.test($('#productPrice').val()))){
			alert("失败啦");
			returnfalse;
		}else{
			alert("是数字");
		}
	}
	
	
	/**
*扩展的基本校验规则,
*/
$.extend($.fn.validatebox.defaults.rules,{
minLength:{//判断最小长度
validator:function(value,param){
value=$.trim(value);//去空格
returnvalue.length>=param[0];
},message:'最少输入{0}个字符。'
},length:{validator:function(value,param){
varlen=$.trim(value).length;
returnlen>=param[0]&&len<=param[1];
},message:"输入内容长度不正确"
},phone:{//验证电话号码
validator:function(value){
return/^d{3,4}-?d{7,9}-?d{2,8}$/i.test(value);
//return/^(((d{2,3}))|(d{3}-))?((0d{2,3})|0d{2,3}-)?[1-9]d{6,7}(-d{1,4})?$/i.test(value);
},message:'格式不正确,请使用下面格式:0571-8888888-001'
},mobile:{//验证手机号码
validator:function(value){
return/^(13|15|18)d{9}$/i.test(value);
},message:'手机号码格式不正确'
},url:{//验证网址格式
validator:function(value){
	//1、简单网站验证
//return/^(http(s)?://)?(www.)?[w-]+.w{2,4}(/)?$/i.test(value);
	//2、ftp、rtsp等复杂网站验证
	return/^((https|http|ftp|rtsp|mms)?://)?(([0-9a-z_!~*'().&=+$%-]+:)?[0-9a-z_!~*'().&=+$%-]+@)?(([0-9]{1,3}.){3}[0-9]{1,3}|([0-9a-z_!~*'()-]+.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].[a-z]{2,6})(:[0-9]{1,4})?((/?)|(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$/i.test(value);
},message:'网址格式不正确'
},idcard:{//验证身份证
validator:function(value){
return/^d{15}(d{2}[A-Za-z0-9])?$/i.test(value);
},message:'身份证号码格式不正确'
},intOrFloat:{//验证整数或小数
validator:function(value){
return/^d+(.d+)?$/i.test(value);
},message:'请输入数字,并确保格式正确'
},currency:{//验证货币
validator:function(value){
return/^d+(.d+)?$/i.test(value);
},message:'货币格式不正确'
},qq:{//验证QQ,从10000开始
validator:function(value){
return/^[1-9]d{4,13}$/i.test(value);
},message:'QQ号码格式不正确'
},integer:{//验证整数/^[+]?[1-9]+d*$/
validator:function(value){
return/^[0-9]*$/i.test(value);
},message:'请输入整数'
},isPort:{//验证整数/^[+]?[1-9]+d*$/
	validator:function(value){
		return/^[0-9]*$/i.test(value)&&value<65536;
	},message:'端口号不正确'
},chinese:{//验证中文
validator:function(value){
return/^[u0391-uFFE5]+$/i.test(value);
},message:'请输入中文'
},english:{//验证英语
validator:function(value){
return/^[A-Za-z]+$/i.test(value);
},message:'请输入英文'
},unnormal:{//验证是否包含空格和非法字符
validator:function(value){
return/.+/i.test(value);
},message:'输入值不能为空和包含其他非法字符'
},username:{//验证用户名
validator:function(value){
return/^[a-zA-Z0-9][a-zA-Z0-9_]+$/i.test(value);
},message:'输入不合法(字母数字开头,允许字母数字下划线)'
},faxno:{//验证传真
validator:function(value){
//return/^[+]{0,1}(d){1,3}[]?([-]?((d)|[]){1,12})+$/i.test(value);
return/^(((d{2,message:'传真号码不正确'
},zip:{//验证邮政编码
validator:function(value){
return/^[1-9]d{5}$/i.test(value);
},message:'邮政编码格式不正确'
},ip:{//验证IP地址/^(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5])$/
validator:function(value){	
return/^(d{1,2}|1dd|2[0-4]d|25[0-5])$/i.test(value);
},message:'IP地址格式不正确'
},name:{//验证姓名,可以是中文或英文
validator:function(value){
return/^[u0391-uFFE5]+$/i.test(value)|/^w+[ws]+w+$/i.test(value);
},message:'请输入姓名'
},carNo:{
validator:function(value){
return/^[u4E00-u9FA5][da-zA-Z]{6}$/.test(value);
},message:'车牌号码无效(例:粤J12350)'
},carenergin:{
validator:function(value){
return/^[a-zA-Z0-9]{16}$/.test(value);
},message:'发动机型号无效(例:FG6H012345654584)'
},email:{
validator:function(value){
return/^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$/.test(value);
},message:'请输入有效的电子邮件账号(例:abc@126.com)'
},msn:{
validator:function(value){
return/^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$/.test(value);
},message:'请输入有效的msn账号(例:abc@hotnail(msn/live).com)'
},same:{
validator:function(value,param){
if($("#"+param[0]).val()!=""&&value!=""){
return$("#"+param[0]).val()==value;
}else{
returntrue;
}
},message:'两次输入的密码不一致!'
},warnmintime:{//判断告警的值只能一级一级的增加,最小值
validator:function(value,param){
value=$.trim(value);//去空格
if(value!="")
for(vari=0;i<param.length;i++){
$(param[i]).val();
if($(param[i]).combobox('getValue')){
vartemp=$.trim($(param[i]).combobox('getValue'));
if(temp!=""&&!isNaN(temp)&&parseInt(value)<=parseInt(temp))
returnfalse;
}
}
returntrue;
},message:'不能小于当前告警的前一级的告警时间'
},warnmaxtime:{//判断告警的值只能一级一级的增加,最大值
validator:function(value,param){
value=$.trim(value);//去空格
if(value!="")
for(vari=0;i<param.length;i++){
$(param[i]).val();
if($(param[i]).combobox('getValue')){
vartemp=$.trim($(param[i]).combobox('getValue'));
if(temp!=""&&!isNaN(temp)&&parseInt(value)>=parseInt(temp))
returnfalse;
}
}
returntrue;
},message:'不能大于当前告警的后一级的告警时间'
},compareDate:{
validator:function(value,param){
returndateCompare($(param[0]).datetimebox('getValue'),value);//注意easyui时间控制获取值的方式
},message:'开始日期不能大于结束日期'
},});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读