user710502
user710502

Reputation: 11469

Regular expressions for numbers

How can I build a regular expression that checks that it must be a number between 0 - 999999999.

Opted for the range validator.

Upvotes: 1

Views: 246

Answers (6)

Pop Catalin
Pop Catalin

Reputation: 62990

Assuming you would want to match numbers that don't start with zero:

Then [1-9]\d{0,8} should do it.

Upvotes: 2

rtpHarry
rtpHarry

Reputation: 13135

If you are trying to validate this inside a <asp:RegularExpressionValidator> then you need to do the same as has been hinted at so far in this thread but you also need a ^ and $ on each end so that it doesnt allow other characters to be added in around it.

^\d{1,9}$

Upvotes: 1

Marco Hurtado
Marco Hurtado

Reputation: 534

Try this:

[0-9]*

It works for me.

Upvotes: 0

Soner G&#246;n&#252;l
Soner G&#246;n&#252;l

Reputation: 98868

If you mean control the number which range, can use rangevalidator

MaximumValue    Specifies the maximum value of the input control
MinimumValue    Specifies the minimum value of the input control

<asp:RangeValidator
ControlToValidate="tbox1"
MinimumValue="1"
MaximumValue="999999999"
Type="Number"
EnableClientScript="false"
runat="server" />

Upvotes: 1

H&#229;vard
H&#229;vard

Reputation: 10080

You could do this:

\d{1,9}
  • \d - digit
  • {1,9} - 1 to 9 repetitions

Upvotes: 1

The simplest thing would be [0-9]{1,9} That will accept all integers between 0 - 999999999. If you want decimals or scientific notation, that can be done too though it's trickier and you might also want to look into some other tool to validate the number value.

Upvotes: 5

Related Questions