2

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 ?

1 Answer 1

2

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

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

See fiddle

I hope it hepls.

Sign up to request clarification or add additional context in comments.

1 Comment

FYI you don't need to explicitly define the validations in JS if you have the HTML5 attributes on the element AND you set parseInputAttributes to true as described here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.