user7917367
user7917367

Reputation:

Regular Expression for Value not greater than 6 with 1 decimal digit?

Values accepted:

6.0
5.9
0.0
1.1
6
5

not accepted:

6.01
6.1
5.99
0.00

what i have tried (1 decimal place) don't know how to limit till 6

^[0-9]+(\.[0-9]{1,1})?$

Upvotes: 1

Views: 181

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626960

You may use

^([0-5](?:\.\d)?|6(?:\.0)?)$

See the regex demo

Details:

  • ^ - start of string
  • ( - start of an alternation group:
    • [0-5](?:\.\d)? - a digit from 0 to 5 followed with an optional sequence of a . followed with a single digit
    • | - or
    • 6(?:\.0)? - 6.0 or 6
  • ) - group end
  • $ - end of string

Upvotes: 3

Related Questions