asp.net - Regex Allowing for Hours in 15 Minute Increments -
I need a regex which restricts entry of 0-24 for one hour. Please keep in mind the following conditions must be fulfilled:
- When the whole part is 0-23, then partial part can be .0, .25, .5, or .75.
- When the whole part is 24, the partial part can be .0
- When no whole part is present, partial part .0, .25, .5, or .75
- Empty string is not allowed
I am confident that the following expression can be tightened, but it is thus far:
(^ (([0-9]) | (1 [0-9]) | (2 [0-3])) (\ ((* * 0 *) | (250 *) | (50 *) | (750 *))) $.?.? (^ 24 (\ 0 *) $). (^ \ ((0+) | (250 *) | (50 *) | (750 *)) $)
Update: regex verification client (javascript) and server (asp .net, c #) both exist.
And the reason for this is why do you need to do this as a regular expression? Changing to a number and doing a few basic checks will be far easier.
Check that the number is a natural number by 4x & lt; = 96, done
The profiles that you are likely to use. NET I think you want it as a regular expression because you are using it for client-side verification. I would seriously consider using a custom validator with client-side javascript.
Javascript for some of these lines:
& lt; Script type = "text / javascript" & gt; Function check time (text) {var tmp = parseFloat (text) * 4; Return TMP & gt; = 0 & amp; Amp; TMP & lt; = 96 & amp; Amp; Mathematics.Syl (TMP) == TMP; } & Lt; / Script & gt; Edit: I was concerned about a few errors while using floats, but seems to work properly for all possible cases.
Comments
Post a Comment