开发者

JavaScript decimal value validation

开发者 https://www.devze.com 2022-12-22 19:28 出处:网络
I want to validate a decimal value in an ASP.NET we开发者_Python百科b page using JavaScript, so that the user can enter numbers with only two decimals. The validation should also consider the current

I want to validate a decimal value in an ASP.NET we开发者_Python百科b page using JavaScript, so that the user can enter numbers with only two decimals. The validation should also consider the current UI culture (e.g. ',' instead of '.'). I use Microsoft's Ajax Framework, is there any function included in the library for such a thing?


If values are separated by spacing you can simply use ^\s*(\d+(?:\.\d+)?)\s+(\d+(?:\.\d+)?)\s*$ regexp (and than use $1 and $2 matches as actual values)

And, more important thing is that all client-side data is insecure by default (because can be forged) so you anyway have to validate it on server.

0

精彩评论

暂无评论...
验证码 换一张
取 消