如何在键按下按钮中仅允许数字和小数. [英] how to allow only numbers and decimal in key down button.

查看:85
本文介绍了如何在键按下按钮中仅允许数字和小数.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我只允许在按键按钮中使用数字和小数.这意味着我可以使用正则表达式允许.75或0.75以及所有数字.

怎么做.

谢谢
Mohd Wasif

Hi,

I want to allow only numbers and decimals in key down button.Means I can allow .75 or 0.75 and all numbers using regular expression.

How to do this.

Thanks
Mohd Wasif

推荐答案

在RegularexpressionValidator的验证表达式属性中使用此代码
^ [0-9]([\.\,] [0-9] {1,3})?
Use this code in validation expression property of RegularexpressionValidator
^[0-9]([\.\,][0-9]{1,3})?



像Winform这样的声音(基于标签).使用KeyPress事件并检查是否按下了键.如果按下的键的密码是数字或小数,则允许或忽略.

带有详细信息的示例可以在这里找到: MSDN:KeyPress事件 [ ^ ]

示例:
Sounds like Winform (based on tag). Use the KeyPress event and check the keypressed. If the keycode of key pressed is number or decimal than allow or else ignore.

Sample with details available here: MSDN: KeyPress Event[^]

Example:
// Determine whether the keystroke is a number from the top of the keyboard.
if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
{
  // Determine whether the keystroke is a number from the keypad.
  if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
  {
     // Check for decimal and then allow.
  }
}


这篇关于如何在键按下按钮中仅允许数字和小数.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆