金额的正则表达式(大于0)且不应为空 [英] Regular Expression for amount(that greater than 0 ) and should not be empty

查看:1063
本文介绍了金额的正则表达式(大于0)且不应为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

heyy ...





我想要一个整数的正则表达式(大于0),不应为空。



如果为空或大于0然后显示错误消息.....我尝试但无法找到两个表达式....任何想法???

解决方案

正则表达式不适合大于值 - 他们根本不知道数字,所以表达式变得相当笨拙:

 ^ 0 * [1-9] \d * 


你最好做这种验证在代码中,而不是作为正则表达式。


如果您使用Asp.net文本框,那么您可以使用RequiredFieldValidator和RegularExpressionValidators作为相同的文本框。输入值大于1的正则表达式为^ [1-9] *。

您的代码应如下所示:

 < span class =code-keyword><   asp:TextBox     ID   =  MyTextBox    runat   =  server  >  <   / asp:TextBox  >  
< asp:RegularExpressionValidator ControlToValidate = MyTextBox ID = regExVal runat = server ErrorMessage = 提供超过1的值。 ValidationExpression = ^ [1-9] * < span class =code-keyword> / >
< asp:RequiredFieldValidator ControlToValidate = MyTextBox ID = reqVal runat = 服务器 ErrorMessage = 提供一些价值。 / >





希望这会有所帮助。


heyy...


I want a Regular Expression for integer(that greater than 0 ) and should not be empty.

if empty or greater than 0 then show error msg..... .I tried but cannot find both expression together ....Any ideaa???

解决方案

Regular expressions are not good for "greater than" values - they don't know about numbers at all, so the expression becomes rather clumsy:

^0*[1-9]\d*


You would be better doing this kind of validation in code, rather than as a regex.


Hi, If you are doing it using Asp.net text box, then you can use RequiredFieldValidator and RegularExpressionValidators for the same text box. Regular Expression for input value more than 1 is "^[1-9]*".
You code should look like:

<asp:TextBox ID="MyTextBox" runat="server"></asp:TextBox>
        <asp:RegularExpressionValidator ControlToValidate="MyTextBox" ID="regExVal" runat="server" ErrorMessage="Provide value more than 1." ValidationExpression="^[1-9]*"/>
        <asp:RequiredFieldValidator ControlToValidate="MyTextBox" ID="reqVal" runat="server" ErrorMessage="Provide some value."/>



Hope this will help.


这篇关于金额的正则表达式(大于0)且不应为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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