简体   繁体   English

如何验证文本框仅包含数字?

[英]How do I validate a textbox to only contain numbers?

如果用户在文本框中输入非数字和数字值,如何只保留数字部分?

Set the property "CausesValidation" to true. 将属性“ CausesValidation”设置为true。 Set your validation to accept only an int or whatever sort of number you are looking for. 将您的验证设置为仅接受一个int或您要查找的任何数字。

Perhaps see: Number validation in required field validator 也许看到: 必填字段验证器中的数字验证

You can use RegularExpressionValidator 您可以使用RegularExpressionValidator

Validate it against your control, with the validation Expression of {0:d} to permit only digits or {0:w} for letters and numbers as well. 根据您的控制进行验证,并使用验证表达式{0:d}仅允许数字或{0:w}来输入字母和数字。

您可以绑定到keydown事件,并且如果密钥不是0-9,则将其设置为true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM