基于Jquery的标签智能验证实现代码

2020-05-17 06:18:27易采站长站整理

break;
case “ncard”:
RegexInputTextOnly($ctrl, strRegex.Card, strError.Card);
break;
case “time”:
RegexInputTextAll($ctrl, strRegex.Time, strError.Time);
break;
case “ntime”:
RegexInputTextOnly($ctrl, strRegex.Time, strError.Time);
break;
case “math”:
RegexInputTextAll($ctrl, strRegex.Math, strError.Math);
break;
case “nmath”:
RegexInputTextOnly($ctrl, strRegex.Math, strError.Math);
break;
case “url”:
RegexInputTextAll($ctrl, strRegex.Url, strError.Url);
break;
case “nurl”:
RegexInputTextOnly($ctrl, strRegex.Url, strError.Url);
break;
case “an”:
RegexInputTextAll($ctrl, strRegex.An, strError.An);
break;
case “nan”:
RegexInputTextOnly($ctrl, strRegex.An, strError.An);
break;
case “phone”:
RegexInputTextAll($ctrl, strRegex.Phone, strError.Phone);
break;
case “nphone”:
RegexInputTextOnly($ctrl, strRegex.Phone, strError.Phone);
break;
case “ddl”:
RegexSelect($ctrl);
break;
case “check”:
RegexInputCheckBoxRadioOnly($ctrl, strError.Check);
break;
case “radio”:
RegexInputCheckBoxRadioOnly($ctrl, strError.Radio);
break;
case “checkgroup”:
RegexInputCheckBoxRadioAll($ctrl, strError.CheckGroup);
break;
case “radiogroup”:
RegexInputCheckBoxRadioAll($ctrl, strError.RadioGroup);
break;
}
}
//标签内容空验证
function RegexNull($ctrl) {
if (strRegex.NoNull.test($ctrl.val())) {
return RegexLen($ctrl);
}
else {
Error($ctrl, strError.NoNull);
return false;
}
}
//验证多个同级一组input(type=radio)标签 或 input(type=checkbox)标签
function RegexInputCheckBoxRadioAll($ctrl, error) {
if ($ctrl.parent().children(“:checked”).length == 0) {
if ($ctrl.parent().children().attr(“super”)) {
//同级标签中可能会有多个[super=’y’]存在,只取一个,用return false;控制,执行一次就从循环体中跳出
$ctrl.parent().children(“[super=’y’]”).each(function () {
Error($(this), error);
return false;
});
}
else {
//同级一组标签一起报错
$ctrl.parent().children(“[type='” + $ctrl.attr(“type”) + “‘]”).each(function () {
Error($(this), error);
});
}
return false;
}
else {
if ($ctrl.parent().children().attr(“super”)) {
$ctrl.parent().children(“[super=’y’]”).each(function () {
Ok($(this));
return false;
});
}
else {
$ctrl.parent().children().each(function () {
Ok($(this));
});
}
return true;
}
}
//验证单个input(type=radio)标签 或 input(type=checkbox)标签
function RegexInputCheckBoxRadioOnly($ctrl, error) {