1
jquery로 양식의 한 입력 필드의 유효성을 검사하는 함수를 작성했습니다. 내 양식에는 2 개의 추가 텍스트 필드가 있습니다. 나는 그들에게 견해 추가 규칙을 추가하는 방법을 모르겠다. 이것은 내가 지금까지 시도한 것이다.JQuery의 입력 필드 유효성 확인
$(document).ready(function() {
$(document).ready(function() {
jQuery.validator.addMethod("url_validation", function (value, element) {
return this.optional(element) || /^(([http|https|HTTPS|HTTP]+:\/\/))?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)[email protected])?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/i.test(value);
}, "error");
$('#myform').validate({
/** this section is working */
rules: {
text_name: {
required: true,
url_validation: true,
maxlength: 2000
}
},
messages: {
text_name: {
required: "Please specify a URL",
url_validation: "The domain you have entered is not a valid domain or sub domain name. Please try again.",
maxlength: "You have exceeded the maximum length"
}
}
/**********************************************************/
/*this is where i tried to add other rules to two of my other textboxes*/
rules: {
text_name2: {
required: true,
url_validation: true,
maxlength: 2000
}
},
messages: {
text_name2: {
required: "Please specify a URL",
url_validation: "The domain you have entered is not a valid domain or sub domain name. Please try again.",
maxlength: "You have exceeded the maximum length"
}
}
/*above thing is not working*/
});
내 HTML에는 유효성을 검사해야하는 다른 두 개의 텍스트 상자가 있습니다. 이 작업을 수행하는 방법?