How to do validations using knockout js validations?

妖精的绣舞 提交于 2019-12-11 03:33:18

问题


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:


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

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

See fiddle

I hope it hepls.



来源:https://stackoverflow.com/questions/16974482/how-to-do-validations-using-knockout-js-validations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!