jQuery UI Widgets Forums Plugins Validator, Drag & Drop, Sortable static custom rules in validators

This topic contains 3 replies, has 2 voices, and was last updated by  toskf072 9 years, 6 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • static custom rules in validators #78186

    toskf072
    Participant

    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?

    static custom rules in validators #78200

    ivailo
    Participant

    Hi toskf072,

    You can set rule: with custom function.

    Best Regards,
    Ivailo Ivanov

    jQWidgets Team
    http://www.jqwidgets.com

    static custom rules in validators #78225

    toskf072
    Participant

    hi~

    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.

    static custom rules in validators #78227

    toskf072
    Participant

    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
    }]
    });

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.