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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -