Custom error message to check for minLength minimum notes

I work with knockout verification. I want to show a custom message for minimum and maximum length. I tried with some options and I can not reach it. If someone has already achieved this, please share with me how I can do this.

this is what i am trying to do now.

var viewModel = {
    firstName: ko.observable().extend({
        minLength: [
            3,
             'Please enter Valid number']

        , maxLength: 10
    }),
}

Do I really have to go to RegEx for this.

+4
source share
2 answers

If you want to provide a custom message, you need to pass the object to the validation rule ( minLength) with a property paramscontaining a parameter and a property messagewith a new message:

var viewModel = {
    firstName: ko.observable().extend({
        minLength: { params: 3, message: "Please enter Valid number" }
        , maxLength: 10
    }),
}

JSFiddle.

+7

Native-Rules, , :

:

var viewModel = {
    firstName: ko.observable().extend({
        minLength: {
            params:3,
            message:'Please enter Valid number'
         }
        , maxLength: 10
    }),
}

, SO

+1

All Articles