regex - Validate a time string (up to one hour) with javascript -
I am looking for a regex pattern to validate a string and see whether it is a valid time or not . It can only happen for one hour. I want to check that a string is a valid time or returned incorrectly.
It should be in mm: ss format
good = 00:00 good = 60: 00 bad = 60:01 bad = 89:09 bad = 3445
Validating number ranges using regex is not the optimal solution to evaluate the easy conditions You need to make a very long pattern, you might be better off investigating if this is a number: number pattern, divide it and check whether the part Whether or not your needs are: Function check time (time) {if (time.match ("^ [0-9] {2}: [0-9] {2} $ ") === null) {return false; } var parts = time.split (':'); If (parts [0]> 60) {return false; } If (parts [0] == 60 and parts [1]> gt; {return false; } Back true; } It is being said that you can create a regex for this if you really want: Function check time (time) {return time.mail ("(60: 00 | [0-5] [0-9]: [0-5] [0-9]) $")! == faucet; } Later this kind of code is very difficult to maintain and read.
Comments
Post a Comment