tags:

views:

112

answers:

4

Hi,

This expression is to check number > 1

^[1-9]+[0-9]*$

  • what is the expression to check if it's greater than a given value, say "99" ?
  • what about a value less than, 99?

Update:

I'm using ASP.NET validation control.

Thanks.

+1  A: 

I agree with @Rowlf comment! You should not need a regex for doing this (unless this is an interview question :) ) . Just use '>'.

Well, your given regex ^[1-9]+[0-9]*$ is matches >=1 not only >1

Gopi
+5  A: 

You say this is homework, so I'll give my answer for greater than 57 instead; you can take the idea and modify it.

/^([6-9][0-9]|5[89]|[1-9][0-9]{2,})$/

If you don't have the {a,} construct,

/^([6-9][0-9]|5[89]|[1-9][0-9][0-9]+)$/
Charles
The last char class should be [0-9]
M42
A: 

Some people, when confronted with a problem, think, "I know, I'll use regular expressions." Now they have two problems. -- http://regex.info/blog/2006-09-15/247

That is all!

Johnsyweb
That's an interesting bit of history, but I don't see how it's helpful.
Gunslinger47
You've edited your post, but now you have two two problems.
Gunslinger47
@Gunslinger47 +1 :-D thanks
Johnsyweb
-1 this isn't an answer
Chad
A: 

I ended up wit ComareValidator. I was trying to do it with CustomValidator. That's way I askd for the regex help.

<asp:CompareValidator ID="CompareValidator1" runat="server" 
                    ControlToValidate="txtAmount" ErrorMessage="Amount must be greater than 99" 
                    Operator="GreaterThan" Type="Integer" ValueToCompare="99">Amount must be greater than 99</asp:CompareValidator>
Narazana
Excellent! Ask StackOverflowers to use regular expressions to solve a problem, then solve it without using regular expressions and accept your own answer. This completely vindicates my answer!
Johnsyweb