This is my requirement for validating a string that could be between 1 and 4 characters long (H stands for hour and M stand for minutes):
1 character = H (digit between 0-9)
2 characters = HH (first H is digit between 0-2, second is digit between 0-9, but if the first one is 2 the second one can only be 0-4)
3 characters = HMM (first H is digit between 0-9, first M is digit between 0-5, second M is digit between 0-9)
4 characters = HHMM (first H is digit between 0-2, second is digit between 0-9, but if the first one is 2 the second one can only be 0-4, first M is digit between 0-5, second M is digit between 0-9)
What makes this challenging is that I don't know the length of the string in advance and the same number could mean different things depending on how long the string is. Any ideas about a JavaScript RegularExpression to validate this?