jQuery UI Widgets › Forums › Plugins › Validator, Drag & Drop, Sortable › static custom rules in validators
Tagged: static custom validator rule
This topic contains 3 replies, has 2 voices, and was last updated by toskf072 9 years, 6 months ago.
-
Author
-
hi~~
i saw api doc about custom validator rules on this url(http://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxvalidator/jquery-validator-api.htm)
but i need some static custom validation rules..
same jquery.validator.addMethod (http://docs.jquery.com/Plugins/Validation/Validator/addMethod)can u help me?
Hi toskf072,
You can set rule: with custom function.
Best Regards,
Ivailo IvanovjQWidgets Team
http://www.jqwidgets.comhi~
i read api doc about “custom function”
(‘#form’).jqxValidator( { rules: [{ input: ‘#passwordInput’,
message: ‘The password is required!’,
action: ‘keyup’,
rule: ‘required’ },
{ input: ‘#passwordInput’,
message: ‘Your password must be between 4 and 12 characters!’,
action: ‘keyup’,
rule: ‘length=4,12’ }] } );Custom Rule Definition. The function returns true or false depending on whether the input is correct or not.
{ input: ‘#birthInput’, message: ‘Your birth date must be between 1/1/1900 and 1/1/2012.’, action: ‘valuechanged’, rule: function () {
var date = $(‘#birthInput’).jqxDateTimeInput(‘value’);
var result = date.dateTime.getFullYear() >= 1900 && date.dateTime.getFullYear() <= 2012;
return result;
}but this case is not static…
i want to reues rules after define rule function.
see the sample..
———————————-
jQuery.validator.addMethod(“domain”, function(value, element) {
return this.optional(element) || /^http:\/\/mycorporatedomain.com/.test(value);
}, “Please specify the correct domain for your documents”);$( “#form” ).validate({
rules: {
passwordInput: {
// custom rule name
domain: true
}
}
});—————————————————–
SO..
how can i make a custom function for “REUSE” ?thanks for your answer.
Ahahaha…
i found a solution.. thank you~~
function domain(input, commit){
//somthing….return true;
}$(‘#form’).jqxValidator({
rules: [{
input: ‘#passwordInput’,
message: ‘The password is required!’,
action: ‘keyup’,
rule: domain
}]
}); -
AuthorPosts
You must be logged in to reply to this topic.