[Frontend] Jquery Validate 客製限制補上

This commit is contained in:
dev01 2022-12-12 09:42:51 +08:00
parent 9ce19eec41
commit 0359a474ca

View File

@ -133,6 +133,17 @@ YT.Math.Random = function (min, max) {
/// </summary>
function jquValAddMethod() {
if ($.validator) {
$.validator.setDefaults({
onkeyup: function (element, event) {
$(element).valid();
},
//errorPlacement: function (error, element) {
// if (element.hasClass("removedTitle"))
// error.insertAfter(element.next("img"));
// else
// error.insertAfter(element);
//}
});
$.validator.addMethod("requiredSelect", function (value, element) {
let selVal = $(element).find(`option:selected`).val();
@ -149,6 +160,14 @@ function jquValAddMethod() {
}
return true;
}, "必須選擇")
$.validator.addMethod("phone", function (phoneNumber, element) {
phoneNumber = phoneNumber.replace(/\s+/g, "");
return phoneNumber.match(/^[0-9]{9,10}$/);
}, "請輸入正確電話號碼格式");
$.validator.addMethod("dbLimit", function (value, element, param) {
return value.length > param;
}, "超出輸入限制");
}
}