I am trying to make sure that the format people input is exactly this :
.match(/\d{1,2}:\d\d\s((AM)|(PM))/)
Meaning that a user could write :
12:30 AM
2:30 PM
But not :
1:2 A
1:30
PM
It needs to be first two digits, followed by a colon, than two more digits, a space, and either AM or PM. But my regex expression isn't that. What am I missing?
\d{1,2}:\d\d\s(AM|PM)\smeans "any whitespace character" rather than simply "a space", and except that you probably want your regex to start with^and end with$so that you know you've matched the entire input string. If you're seeing behavior that makes you think your regex does something different, then the problem is probably with the surrounding code. (Perhaps you're misunderstanding what thematchmethod does?)