Syntax for regular expression that is a number?

M

Mark B

What would the regular expression syntax be to validate that a field's input
is simply any integer number >=1?
 
H

Hans Kesting

Anon User wrote :
Mark, here it is: ^\d+$

not quite, as that would allow "0", which was not the question.

use: ^[1-9]\d*$
this does not allow leading zeroes or a single zero.

Hans Kesting
 
G

Guest

Anon User wrote :
Mark, here it is: ^\d+$

not quite, as that would allow "0", which was not the question.

use: ^[1-9]\d*$
this does not allow leading zeroes or a single zero.

Hans Kesting

Ah, you're right, your pattern is correct, thanks
 
J

Juan T. Llibre

re:
!> Mark, here it is: ^\d+$

I don't think so.

This regex defines "any positive integer number >=1" :

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

Using ASP.NET's range validator control will make the job easier, though.



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
=========================
What would the regular expression syntax be to validate that a field's input
is simply any integer number >=1?

Mark, here it is: ^\d+$
 
A

Andrew Morton

Hans said:
Anon User wrote :
Mark, here it is: ^\d+$

not quite, as that would allow "0", which was not the question.

use: ^[1-9]\d*$
this does not allow leading zeroes or a single zero.

But 007 satisfies the OP's requirement...

Andrew
 
M

Mark B

Thanks all.

Actually we wouldn't want 007. It's just a text field on a page for the user
to enter the number of users they want their software license to cover.

I can't bring myself to put an upper limit on it (e.g. using the range
validator) so I decided to go for ^[1-9]\d*$.



Andrew Morton said:
Hans said:
Anon User wrote :
What would the regular expression syntax be to validate that a
field's input is simply any integer number >=1?

Mark, here it is: ^\d+$

not quite, as that would allow "0", which was not the question.

use: ^[1-9]\d*$
this does not allow leading zeroes or a single zero.

But 007 satisfies the OP's requirement...

Andrew
 
J

Jesse Houwing

Hello Mark,
Thanks all.

Actually we wouldn't want 007. It's just a text field on a page for
the user to enter the number of users they want their software license
to cover.

I can't bring myself to put an upper limit on it (e.g. using the range
validator) so I decided to go for ^[1-9]\d*$.

If you have a datatype in use (say an int), you will have an upper limit
enforced by the number of bytes...

Just a thought... this regex can cause parsing problems of someone were to
type:

99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

and hit enter...

Jesse

Hans said:
Anon User wrote :


What would the regular expression syntax be to validate that a
field's input is simply any integer number >=1?

Mark, here it is: ^\d+$

not quite, as that would allow "0", which was not the question.

use: ^[1-9]\d*$
this does not allow leading zeroes or a single zero.
But 007 satisfies the OP's requirement...

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top