I have a textbox where I get the time as HH:MM AM/PM (like 5:30 PM). I want to validate the time: whether it is 1 hour greater than the current time or not. How can I do this using JavaScript?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
First of all, I'd suggest using an existing date-handling library like Datejs. You will have the benefit if a time-tested library with a comprehensive set of methods.
With Datejs, your answer is as simple as:
If you'd rather not use Datejs, you can use regular expressions to parse the time before validating it. I've written a set of functions, along with unit tests which run in the Firebug console, that do just that: