/*********************************
* themes, rules, and i18n support
* locale: chinese; 中文
*********************************/
(function ($) {
var validatorroot;
$('script[src*=validator]').each(function(){
var s=this.src;
if(s.match(/jquery.validator[^\/]*\.js/i)){validatorroot=s.replace(/[\?#].*$/, '').replace(/(^|[\/\\])[^\/]*$/, '$1');return false;}
});
var validatorcss=validatorroot+"css/jquery.validator.css"
$('head').append('');
/* global configuration
*/
$.validator.config({
//stoponerror: true,//遇到错误后停止执行下面的判断
//theme: 'yellow_right_effect',
defaultmsg: "{0}格式不正确",
loadingmsg: "正在验证...",
// custom rules
rules: {
digits: [/^\d+$/, "请输入整数"]
,dot: [/^\d{1,4}(?:\.\d{0,2})?$/, "请输入数字"]//新增的小数支持
,letters: [/^[a-z]+$/i, "{0}只能输入字母"]
,tel: [/^(?:(?:0\d{2,3}[- ]?[1-9]\d{6,7})|(?:[48]00[- ]?[1-9]\d{6}))$/, "电话格式不正确"]
,mobile: [/^1[3-9]\d{9}$/, "手机号格式不正确"]
,email: [/^[\w\+-]+(\.[\w\+-]+)*@[a-z\d-]+(\.[a-z\d-]+)*\.([a-z]{2,4})$/, "邮箱格式不正确"]
,qq: [/^[1-9]\d{4,}$/, "qq号格式不正确"]
,date: [/^\d{4}-\d{1,2}-\d{1,2}$/, "请输入正确的日期,例:yyyy-mm-dd"]
,time: [/^([01]\d|2[0-3])(:[0-5]\d){1,2}$/, "请输入正确的时间,例:14:30或14:30:00"]
,id_card: [/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[a-z])$/, "请输入正确的身份证号码"]
,url: [/^(https?|ftp):\/\/[^\s]+$/i, "网址格式不正确"]
,postcode: [/^[1-9]\d{5}$/, "邮政编码格式不正确"]
,chinese: [/^[\u0391-\uffe5]+$/, "请输入中文"]
,username: [/^\w{5,20}$/, "请输入5-20位数字、字母、下划线"]
,password: [/^[0-9a-za-z.]{6,16}$/, "密码由6-16位数字、字母组成"]
,fieldname: [/^\w{2,20}$/, "请输入2-20位数字、字母、下划线"]
,nickname: [/^[0-9a-za-z\u0391-\uffe5]{2,10}$/, "昵称由2-10字符组成,不含特殊符号"]
,accept: function (element, params){
if (!params) return true;
var ext = params[0];
return (ext === '*') ||
(new regexp(".(?:" + (ext || "png|jpg|jpeg|gif") + ")$", "i")).test(element.value) ||
this.rendermsg("只接受{1}后缀", ext.replace('|', ','));
}
}
});
/* default error messages
*/
$.validator.config({
messages: {
required: "{0}不能为空",
remote: "{0}已被使用",
integer: {
'*': "请输入整数",
'+': "请输入正整数",
'+0': "请输入正整数或0",
'-': "请输入负整数",
'-0': "请输入负整数或0"
},
match: {
eq: "{0}与{1}不一致",
neq: "{0}与{1}不能相同",
lt: "{0}必须小于{1}",
gt: "{0}必须大于{1}",
lte: "{0}必须小于或等于{1}",
gte: "{0}必须大于或等于{1}"
},
range: {
rg: "请输入{1}到{2}的数",
gt: "请输入大于或等于{1}的数",
lt: "请输入小于或等于{1}的数"
},
checked: {
eq: "请选择{1}项",
rg: "请选择{1}到{2}项",
gt: "请至少选择{1}项",
lt: "请最多选择{1}项"
},
length: {
eq: "请输入{1}个字符",
rg: "请输入{1}到{2}个字符",
gt: "请至少输入{1}个字符",
lt: "请最多输入{1}个字符",
eq_2: "",
rg_2: "",
gt_2: "",
lt_2: ""
}
}
});
/* themes
*/
var tpl_arrow = '◆◆';
$.validator.settheme({
'simple_right': {
formclass: 'n-simple',
msgclass: 'n-right'
},
'simple_bottom': {
formclass: 'n-simple',
msgclass: 'n-bottom'
},
'yellow_top': {
formclass: 'n-yellow',
msgclass: 'n-top',
msgarrow: tpl_arrow
},
'yellow_bottom': {
formclass: 'n-yellow',
msgclass: 'n-bottom',
msgarrow: tpl_arrow
},
'yellow_right': {
formclass: 'n-yellow',
msgclass: 'n-right',
msgarrow: tpl_arrow
},
'yellow_right_effect': {
formclass: 'n-yellow',
msgclass: 'n-right',
showok: '',
msgarrow: tpl_arrow,
msgshow: function($msgbox, type){
var $el = $msgbox.children();
if ($el.is(':animated')) return;
if (type === 'error') {
$el.css({
left: '20px',
opacity: 0
}).delay(100).show().stop().animate({
left: '-4px',
opacity: 1
}, 150).animate({
left: '3px'
}, 80).animate({
left: 0
}, 80);
} else {
$el.css({
left: 0,
opacity: 1
}).fadein(200);
}
},
msghide: function($msgbox, type){
var $el = $msgbox.children();
$el.stop().delay(100).show().animate({
left: '20px',
opacity: 0
}, 300, function(){
$msgbox.hide();
});
}
}
});
})(jquery);