Regular Expression (RegEx) for incremental watches

I need to accept only input that complies with these rules ...

  • 0.25-24
  • Increments 0.25 (.00, .25, .50, .75)
  • The first digit is optional.
  • Trailing zeros are optional.

Examples of some valid entries:

  • 0.25
  • 0.50
  • 0.5
  • 1
  • 1.0
  • 5.50
  • 23.75
  • 24 (maximum allowed)
  • UPDATE: nothing, null / blank, should also be accepted as valid

An example of some invalid entries:

  • 0
  • 0,0
  • +0.00
  • 0.0
  • 0.00
  • 24.25
  • 1

, RegEx - , , , , . , , 24 , , ? , 24 , RegEx, ? ColdFusion , , 0-24. , ColdFusion , RegEx, . , :

^\d{0,2}((\.(0|00|25|5|50|75))?)$

http://regex101.com/r/iS7zM3

, 0-24 . , . !

+3
3

\d{0,2} (?:1[0-9]?|2[0-4]?|[3-9])?, 1 24 ( ).

(?:\.(?:00?|25|50?|75))? - (?:\.(?:[05]0?|[27]5))?, .

24.25, lookahead (?!24\.[^0]) -, 24.0 24.00, , , 24 24/24.0/24.00 :

(?x)
    # checks for 24
    ^24$|^24\.00?$
    |
    # integer part
    ^
    (?:1[0-9]?|2[0-3]?|[3-9]|0(?=\.[^0])|(?=\.[^0]))
    # decimal part
    (?:\.(?:00?|25|50?|75))?
    $

0(?=\.[^0]), lookahead, 0, char ., ( 0.0 0.00 ).

(?x) , - , - # . ( , , \x23 .)

, pure-CFML:

IsNumeric(Num)
AND Num GT 0
AND Num LTE 24
AND NOT find('.',Num*4)

, ...

+6

( ):

^
(?:
(?:[1-9]|1\d|2[0-3])(?:\.(?:[05]0?|[27]5))?   # Non-zeros with optional decimal
|
0?(?:\.(?:50?|[27]5))                         # Decimals under 1
|
24(?:\.00?)?                                  # The maximum
)
$

:

^(?:(?:[1-9]|1\d|2[0-3])(?:\.(?:[05]0?|[27]5))?|0?(?:\.(?:50?|[27]5))|24(?:\.00?)?)$

regex101

+3

^([0-1]?[0-9]|2[0-4])((\.(0|00|25|5|50|75))?)$

, 0-9, , 0 1.

2, 0-4.

, . parens, , :

^([0-1]?[0-9]|2[0-4])(\.(0|00|25|5|50|75))?$

0

All Articles