coldfusion - Regular Expression (RegEx) For Hours with Increments -


I have to accept the inputs that meet these rules ...

  1. 0.25 -24
  2. Increase of .25 (.00, .25, .50, .75)
  3. The first digit is not required.
  4. Example of some valid listings:

    1. 0.25
    2. .50
    3. 1
    4. 1.75
    5. 23.75
    6. 24 (maximum permissions)
    7. update

    8. Update: Nothing, empty / blank should also be accepted as valid

    Some invalid entries Example:

    1. 0
    2. .00
    3. 0.0
    4. 0.00
    5. 24.25
    6. -1

    I understand that RegEx is a pattern matching language, so this ranges, at least, And is not great compared to checking so to verify whether it is less than 24 or equal, I find a pattern, right? So there are 24 possible peters, which would make it a long RegEx, am I understanding it correctly? I can use ColdFusion to make a check to make sure that it is in the 0-24 range. This is not the end of the world if I have used coldfusion for this part, but all of them get in regx It would be good to do so if it does not have to be too long. This is what I have done so far:

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

    It handles it too much except for a 0-24 range probe or just a check for a zero, but I keep it away Thanks also!

    change \ d {0,2} < / Code> to (?: 1 [0-9]? | 2 [0-4]? | [3- 9])? and match it from 1 to 24 (or nothing)

    You can go to (?:? (? (? (? 00? | 25 | 50? | 75)) - You can go to (?: \. (?: [05] 0? | [27] 5))? But this may obscure a little more distant intent.

    To exclude 24.25, you might use a negative LookIahad To prevent anything from (? 24 \. [^ 0]) 24.0 or 24.00, but mainly for excluding 24, 24 / 24.0 / 24.00 for one Specific checks include Start:

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

    Includes a check for 0 (? = \. [^ 0]) , which would allow only the initial 0 Uses a positive form for if the next letter is a . After that a non-zero (0.0 and 0.00 are not allowed).

    (? X) allows the flag to ignore white space, allowing readable Rijaks in your code - for all squash in a row better - and it can start also makes clear that # to use to clarify parts of the line comments to escape with a pattern of (literally white space and hash backslash , Or for the hash like \ x23 by anco It can be.)

    For comparison, here is a pure-Sifmel way to do it:

      IsNumeric (Num) and the number of GM 0 No. LTE 24 and not ('.', Number * 4)  

    Now, are you really sure that it is better as a reggex ...


Comments