Ajax异步方式实现登录与參数的校验
2021-06-30 21:04
$/ \\\/\‘\"]*)|.{0,5})$|\s/ m[2] : GetFullYear(parseInt(m[3], 10));
break;
case "dmy" :
m = op.match(new RegExp("^\\s*(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))\\s*$"));
if(m == null ) return false;
day = m[1];
month = m[3]--;
year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10));
break;
default :
break;
}
var date = new Date(year, month, day);
return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate());
function GetFullYear(y){return ((y30 ? "20" : "19") + y)|0;}
}
};
var Validation = {
notNull: function($container, $element, content, errorMessage) {
if (isNull(content)) {
showErrorMessage($container, $element, errorMessage);
return false;
}
return true;
},
email: function($container, $element, content, errorMessage) {
var reg = new RegExp(/^(\w)+(\.\w+)*@(\w)+((\.\w{2,3}){1,3})$/);
if (!reg.test(content)) {
showErrorMessage($container, $element, errorMessage);
return false;
}
return true;
},
serialNmuber: function($container, $element, content, errorMessage) {
var reg = new RegExp(/^[0-9a-zA-Z_-]*$/);
if (!reg.test(content)) {
showErrorMessage($container, $element, errorMessage);
return false;
}
return true;
},
number: function($container, $element, content, errorMessage) {
var reg = new RegExp(/^[0-9]*$/);
if (!reg.test(content)) {
showErrorMessage($container, $element, errorMessage);
return false;
}
return true;
},
humanName: function($container, $element, content, errorMessage) {
var reg = new RegExp(/(^[A-Z a-z]*$)|(^[\u4e00-\u9fa5]*$)/);
if (!reg.test(content)) {
showErrorMessage($container, $element, errorMessage);
return false;
}
return true;
},
checkByRegExp: function($container, $element, regExp, content, errorMessage){
var reg = new RegExp(regExp);
if (!reg.test(content)) {
showErrorMessage($container, $element, errorMessage);
return false;
}
return true;
}
};
/**
* 检查是否为空
*/
var isNull = function(item){
if(item == null || item == "" || item.replace(/(^\s*)|(\s*$)/g, "") == "" ){
return true;
}
return false;
};
/**
* 显示提示信息
*/
var showErrorMessage = function($container, $element, content){
$element.popover({
content: content,
trigger: ‘manual‘,
container: $container
}).popover(‘show‘).on({
‘blur‘: function(){
$element.popover(‘destroy‘);
$element.parent().removeClass(‘has-error‘);
},
‘keydown‘: function(){
$element.popover(‘destroy‘);
$element.parent().removeClass(‘has-error‘);
}
}).focus().parent().addClass(‘has-error‘);
};
Validator = {
Require : {expression:/.+/,errorMsg:"该字段不能为空"},
Email : {expression:/^\w+([-+.]\w+)*@\w+([-.]\\w+)*\.\w+([-.]\w+)*$/,errorMsg:"Email格式不对"},
Mobile:{expression:/^(1[3|5|8]{1}\d{9})$/,errorMsg:"手机格式不对"},
TelePhone:{expression:/^(((0\d{2,3}-)?\d{7,8}(-\d{4})?))$/,errorMsg:"电话号码格式不对"},
IdCard:{expression:/^\d{15}(\d{2}[A-Za-z0-9])?
文章标题:Ajax异步方式实现登录与參数的校验
文章链接:http://soscw.com/index.php/essay/100013.html