Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you specify custom error messages when validate() fails? #13

Open
Marak opened this issue Dec 23, 2010 · 1 comment
Open

How do you specify custom error messages when validate() fails? #13

Marak opened this issue Dec 23, 2010 · 1 comment

Comments

@Marak
Copy link

Marak commented Dec 23, 2010

     this.property('to', 'string', {
       required: true,
       message: "The to field is required to send an email."
     });
@janpieper
Copy link

would be great to be able to specify more than one error message because in most cases there isn't only one validation rule.

this.property("password", "string", {
    assert: function(val) {
        if (val.length <= 6 || val.length => 30) {
            return false; // validation failed due to invalid length
        } else if (val.match(/^[a-z0-9_]+$/) != val) {
            return false; // not allowed characters in use
        }
        return true;
    }
});

or

this.property("password", "string", {
    assert: function(val) {
        var errors = [];
        if (val.length <= 6 || val.length => 30) {
            errors[errors.length] = "validation failed due to invalid length";
        }
        if (val.match(/^[a-z0-9_]+$/) != val) {
            errors[errors.length] = "not allowed characters in use";
        }
        return errors.length == 0;
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants