Home > front end >  Accept values from 1 to 30 including two decimal points (i.e. 1.0 to 30.0)
Accept values from 1 to 30 including two decimal points (i.e. 1.0 to 30.0)

Time:10-06

I would like a Regular Expression (regex) to accept values from 1 to 30 including two decimal points (i.e. 1.00 to 30.00).

I have managed to use this:

^[1-9]{1}$|^[1-2]{1}[0-9]{1}$|^30$

but it does not accept decimal points

CodePudding user response:

Regex matching from 1 up to 30.00 inclusively:

^(?:(?:[1-9]|[12]\d)(?:[.,]\d{1,2})?|30(?:[.,]00?)?)$

Try it.

Regex matching from 0 up to 30.00 inclusively (answers the version of the question before edit):

^(?:[12]?\d(?:[.,]\d{1,2})?|30(?:[.,]00?)?)$

Try it.

  • Related