如何仅允许文本框字段的数字而不允许任何空格 [英] How do I allow only numbers for a text box field and not any whitespaces

查看:68
本文介绍了如何仅允许文本框字段的数字而不允许任何空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有文本框,我只需要允许数字,使用^ [0-9] + $这个特殊的正则表达式将无法正常工作,因为,如果我们在文本框字段中只输入空格,它将验证,并且page.isvalid变为true,这怎么可能

这是发生在asp.net 4,.net4框架



我尝试了什么:



尝试了^ [^ / s] [0-9] + $但没有想要的结果

i've text box and i need to allow only numbers, using ^[0-9]+$ this particular regex expression will not work perfectly, because, if we enter only white spaces in the textbox field it'll validate, and page.isvalid becomes true, how is this possible
this is happening asp.net 4, .net4 framework

What I have tried:

have tried ^[^/s][0-9]+$ but no desired result

推荐答案

这个特殊的正则表达式将无法正常工作,因为,如果我们只在文本框字段中输入空格,它将验证,并且page.isvalid变为true,这怎么可能

这是发生在asp.net 4,.net4框架上



我尝试了什么:



尝试了^ [^ / s] [0-9] +
this particular regex expression will not work perfectly, because, if we enter only white spaces in the textbox field it'll validate, and page.isvalid becomes true, how is this possible
this is happening asp.net 4, .net4 framework

What I have tried:

have tried ^[^/s][0-9]+


但没有想要的结果


之前已经问过这个解决方案可以在网上找到:

c# - RegularExpressionValidator未在空白区域条目上触发 - Stack Overflow [ ^ ]。
This has been asked before and the solution can be found in the net:
c# - RegularExpressionValidator not firing on white-space entry - Stack Overflow[^].


这篇关于如何仅允许文本框字段的数字而不允许任何空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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