扩展验证vilidatebox

 1 $.extend($.fn.validatebox.defaults.rules,{
002  2 minLength:{// 判断最小长度
003  3 validator:function(value,param) {
004  4 returnvalue.length>=param[0];
005  5 },
006  6 message:'最少输入 {0} 个字符。'
007  7 },
008  8 length:{validator:function(value,param){
009  9 varlen=$.trim(value).length;
010 10 returnlen>=param[0]&&len<=param[1];
011 11 },
012 12 message:"输入内容长度必须介于{0}和{1}之间."
013 13 },
014 14 phone:{// 验证电话号码
015 15 validator:function(value) {
016 16 return/^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value);
017 17 },
018 18 message:'格式不正确,请使用下面格式:020-88888888'
019 19 },
020 20 mobile:{// 验证手机号码
021 21 validator:function(value) {
022 22 return/^(13|15|18)\d{9}$/i.test(value);
023 23 },
024 24 message:'手机号码格式不正确'
025 25 },
026 26 idcard:{// 验证身份证
027 27 validator:function(value) {
028 28 return/^\d{15}(\d{2}[A-Za-z0-9])?$/i.test(value);
029 29 },
030 30 message:'身份证号码格式不正确'
031 31 },
032 32 intOrFloat:{// 验证整数或小数
033 33 validator:function(value) {
034 34 return/^\d+(\.\d+)?$/i.test(value);
035 35 },
036 36 message:'请输入数字,并确保格式正确'
037 37 },
038 38 currency:{// 验证货币
039 39 validator:function(value) {
040 40 return/^\d+(\.\d+)?$/i.test(value);
041 41 },
042 42 message:'货币格式不正确'
043 43 },
044 44 qq:{// 验证QQ,从10000开始
045 45 validator:function(value) {
046 46 return/^[1-9]\d{4,9}$/i.test(value);
047 47 },
048 48 message:'QQ号码格式不正确'
049 49 },
050 50 integer:{// 验证整数
051 51 validator:function(value) {
052 52 return/^[+]?[1-9]+\d*$/i.test(value);
053 53 },
054 54 message:'请输入整数'
055 55 },
056 56 chinese:{// 验证中文
057 57 validator:function(value) {
058 58 return/^[\u0391-\uFFE5]+$/i.test(value);
059 59 },
060 60 message:'请输入中文'
061 61 },
062 62 english:{// 验证英语
063 63 validator:function(value) {
064 64 return/^[A-Za-z]+$/i.test(value);
065 65 },
066 66 message:'请输入英文'
067 67 },
068 68 unnormal:{// 验证是否包含空格和非法字符
069 69 validator:function(value) {
070 70 return/.+/i.test(value);
071 71 },
072 72 message:'输入值不能为空和包含其他非法字符'
073 73 },
074 74 username:{// 验证用户名
075 75 validator:function(value) {
076 76 return/^[a-zA-Z][a-zA-Z0-9_]{5,15}$/i.test(value);
077 77 },
078 78 message:'用户名不合法(字母开头,允许6-16字节,允许字母数字下划线)'
079 79 },
080 80 faxno:{// 验证传真
081 81 validator:function(value) {
082 82 // return /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/i.test(value);
083 83 return/^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value);
084 84 },
085 85 message:'传真号码不正确'
086 86 },
087 87 zip:{// 验证邮政编码
088 88 validator:function(value) {
089 89 return/^[1-9]\d{5}$/i.test(value);
090 90 },
091 91 message:'邮政编码格式不正确'
092 92 },
093 93 ip:{// 验证IP地址
094 94 validator:function(value) {
095 95 return/d+.d+.d+.d+/i.test(value);
096 96 },
097 97 message:'IP地址格式不正确'
098 98 },
099 99 name:{// 验证姓名,可以是中文或英文
100100 validator:function(value) {
101101 return/^[\u0391-\uFFE5]+$/i.test(value)|/^\w+[\w\s]+\w+$/i.test(value);
102102 },
103103 message:'请输入姓名'
104104 },
105105 carNo:{
106106 validator:function(value){
107107 return/^[\u4E00-\u9FA5][\da-zA-Z]{6}$/.test(value); 
108108 },
109109 message:'车牌号码无效(例:粤J12350)'
110110 },
111111 carenergin:{
112112 validator:function(value){
113113 return/^[a-zA-Z0-9]{16}$/.test(value); 
114114 },
115115 message:'发动机型号无效(例:FG6H012345654584)'
116116 },
117117 email:{
118118 validator:function(value){
119119 return/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(value); 
120120 },
121121 message:'请输入有效的电子邮件账号(例:<A href="mailto:abc@126.com">abc@126.com</A>)'
122122 },
123123 msn:{
124124 validator:function(value){
125125 return/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(value); 
126126 },
127127 message:'请输入有效的msn账号(例:abc@hotnail(msn/live).com)'
128128 },same:{
129129 validator:function(value,param){
130130 if($("#"+param[0]).val() !=""&&value!=""){
131131 return$("#"+param[0]).val() ==value; 
132132 }else{
133133 returntrue;
134134 }
135135 },
136136 message:'两次输入的密码不一致!'
137137 }
138138 });
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值