如果条件为整数和浮点数 [英] If Condition for Both Integer and float

查看:162
本文介绍了如果条件为整数和浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,



这里我有一个问题,我的文本框只允许整数和浮点值。如果eny别的东西会给出错误信息。请在下面找到我的代码。





  if (!int.TryParse(x, out   value  ))
{
ModelState.AddModelError( 错误);
}







请帮帮我



在此先感谢...

解决方案

如果它应该 int float 你可以 TryParse 两者并且只有在两者都失败时才会出错。


正则表达式可以帮助你。试试这个正则表达式:

 ^ \((?=。)([+  - ]?([0-9] *)(\。([0- 9] +))?)\)






- 艾美

Hello All,

Here I have one problem my text box allowed only integer and float value. if eny thing else will give error message.Please find my code Below.


if (!int.TryParse(x, out value))
                   {
                       ModelState.AddModelError("", "Error");
                   }




Please help me

Thanks in advance...

解决方案

If it should be either a int or a float you could TryParse both and give error only if both fail.


Regex may help you. Try this Regular Expression:

^\((?=.)([+-]?([0-9]*)(\.([0-9]+))?)\)




--Amy


这篇关于如果条件为整数和浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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