/**
* 增加大于某个值的验证
*/
window.ParsleyValidator.addValidator(
'greater',
function (value,greater) {
if(isNaN(value)||isNaN(greater)){
return false;
}
return parseFloat(value)>parseFloat(greater);
}, 30);
/**
* 小于某个值的验证
*/
window.ParsleyValidator.addValidator(
'lesser',
function (value,lesser) {
if(isNaN(value)||isNaN(lesser)){
return false;
}
return parseFloat(value)<=parseFloat(lesser);
}, 30);
/**
* 条件必须验证
*/
window.ParsleyValidator.addValidator(
'conditionalrequired',
function (value,requirements) {
if (requirements[1] == $(requirements[0]).val() && '' == $.trim(value))
return false;
return true;
}, 30);
/**
* 手机号验证
*/
window.ParsleyValidator.addValidator(
'mobile',
function (value) {
var exp = /^1[345789][0-9]{9}$/;
return value&&exp.test(value);
}, 30);
/**
* 邮编验证
*/
window.ParsleyValidator.addValidator(
'zipcode',
function (value) {
var exp = /^[1-9][0-9]{5}$/;
return value&&exp.test(value);
}, 30);
/**
* 密码验证
*/
window.ParsleyValidator.addValidator(
'password',
function (value) {
var all = /^[da-zA-Z`=-[];',.~!@#$%^&*\/()_+|{}:"<>?]+$/;
var numReg = /[d]+/, charReg = /[a-zA-Z]+/, specReg = /[`=-[];',.~!@#$%^&*\/()_+|{}:"<>?]+/;
return value&&all.test(value)&&numReg.test(value)&&charReg.test(value)&&specReg.test(value);
}, 30);
/**
* 手机号或邮箱验证
*/
window.ParsleyValidator.addValidator(
'mobileandemail',
function (value) {
var emailPattern= /^[w!#$%&'*+/=?^_`{|}~-]+(?:.[w!#$%&'*+/=?^_`{|}~-]+)*@(?:[w](?:[w-]*[w])?.)+[w](?:[w-]*[w])?$/;
var mobilePattern = /^1[345789][0-9]{9}$/;
return value&&(emailPattern.test(value)||mobilePattern.test(value));
}, 20);
/**
* 多邮箱验证
*/
window.ParsleyValidator.addValidator(
'emails',
function (value,counts) {
if(!counts||Object.prototype.toString.call( counts ) !== '[object Array]'||counts.length!=2){
return false;
}
var emailsPatternBase = "[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?";
var reg = "^" + emailsPatternBase + "([,]" + emailsPatternBase + "){" + (counts[0]-1) + "," + (counts[1]-1) + "}[,]?$";
var emailsReg = new RegExp(reg);
return value&&emailsReg.test(value);
}, 30);
/**
* 小数位数验证
*/
window.ParsleyValidator.addValidator(
'numberdigit',
function (value,digit) {
if(digit==null||digit=='undefined'){
return false;
}
if(typeof digit !='number'){
return false;
}
var reg='^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d{1,'+digit+'})?$'
var numberReg = new RegExp(reg);
return value&&(numberReg.test(value));
}, 30);
/**
* 视频格式验证
*/
window.ParsleyValidator.addValidator(
'video',
function (value) {
if(value==null||value==''){
return false;
}
var video = value.indexOf('?') == -1 ? value : value.substring(0, value.indexOf('?'));
return video.substring(video.length-4).toLowerCase() === '.swf';
}, 30);