在asp.net中验证整数和浮点值 [英] Validating Integer and float value in asp.net

查看:84
本文介绍了在asp.net中验证整数和浮点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个文本框,我必须验证asp.net中的整数或浮点数.

请让我知道,如何实施?

谢谢你
莫哈末Wasif

Hi All,

I have a textbox in that I have to validate integer or float in asp.net.

Please let me know, how to implement it?

Thanking You
Mohd. Wasif

推荐答案

查看此链接

http://aspdotnet-sequel.blogspot.com/2009/05/aspnet-textbox-validate-integer-float.html [ ^ ]

http://syntaxhelp.com/JavaScript/validation/check-int-float [ ^ ]
see this links

http://aspdotnet-sequel.blogspot.com/2009/05/aspnet-textbox-validate-integer-float.html[^]

http://syntaxhelp.com/JavaScript/validation/check-int-float[^]


我接受了从您的问题来看,验证将在服务器端完成,因此请尝试如下操作:
取决于您需要哪种验证.首先,请确保您在上述字段中接收到的文本确实是整数或双精度数(不要使用浮点数,因为它们与双精度数相比没有任何优势).这可以通过使用double.TryParse(String strVal, out double value)int.TryParse(String strVal, out int value)方法来实现.
转换成功后,您可以检查是否包含在范围或上限或下限等中.

如果您有任何疑问,请给我留言!

-MRB
I took from your question that the validation is to be done on the server side so try it like this:
Depends on what kind of validation you need. First make sure the text you received in said fields is really and integer or a double (don''t use floats as they don''t have any advantage over doubles). This can be achieved by using double.TryParse(String strVal, out double value) or int.TryParse(String strVal, out int value) methods.
When the conversion was successful you can check for containment in a range or an upper or lower bound etc.

If you have any doubts leave me a comment!

-MRB


您可以借助Javascript
这是验证点击 ME [
You can take a help of Javascript
Here is the way to validate click ME[^]


这篇关于在asp.net中验证整数和浮点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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