Nish
Nish

Reputation: 169

How to do validations using knockout js validations?

I want to do client side validations using knockout js.

for example , I want to validate below element as required, number only and it should not exceed 10 digits? How can we achieve this using knockout js validation ?

<input data-bind='value: phone' required digits='true' maxlength='10' />

any thoughts ?

Upvotes: 2

Views: 4026

Answers (1)

Damien
Damien

Reputation: 8987

Take a look at Knockout.validation and use this obsevable extension :

phoneNumber.extend({digit: true}).extend({ maxLength: 10 });

See fiddle

I hope it hepls.

Upvotes: 2

Related Questions