Jump to content

regex to accept a whole number, or a decimal number


sid0972

Recommended Posts

1. The entire decimal part should be optional, not just the decimal point. Otherwise you're setting a minimum number of digits (two, with the \d+ and the \d{1,}).

2. {1,2,3} is entirely invalid syntax. It's a range, not a list of possible counts.

 

I'd add parentheses to PaulRyan's solution.

/^\d+(\.\d{1,3})?$/

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.