如何验证在winform仅数? [英] How to validate only number in winform?

查看:112
本文介绍了如何验证在winform仅数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何验证对数字不使用按键选项
为什么心不是 Char.IsNumber .IsDigit 工作
或我应该使用正则表达式的表达式验证

 私人布尔ValidateContact()
{
如果(Char.IsNumber(textBox4.Text)){
返回真;
}


解决方案

您可以简单地解析数

 私人布尔ValidateContact()
{
INT VAL;
如果(int.TryParse(textBox4.Text,出VAL))
{
返回真;
}
,否则
{
返回FALSE;
}
}

您正试图调用为编写的方法字符字符串。你必须单独做所有这些,或使用更容易使用,就像上面的代码的方法。


How to validate for numbers without using keypress option why isnt Char.IsNumber or .IsDigit working or should I use regex expression for validation

private bool ValidateContact()
{
    if (Char.IsNumber(textBox4.Text)){
        return true;
}

解决方案

You could simply parse the number:

private bool ValidateContact()
{
    int val;
    if (int.TryParse(textBox4.Text, out val))
    {
       return true;
    }
    else
    {
        return false;
    }
}

You are trying to call a method that is written for char for string. You have to do them all separately, or use a method that is much easier to use, like the above code.

这篇关于如何验证在winform仅数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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