Skip to content

Instantly share code, notes, and snippets.

@percyperez
Created December 14, 2012 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save percyperez/4288072 to your computer and use it in GitHub Desktop.
Save percyperez/4288072 to your computer and use it in GitHub Desktop.
Regular expression for validating time hh:mm am|pm
re = /(^(\d{1,2}):(\d{2})\s?(?:am|pm)?)$|^\d{1}(?:am|pm)$/i;
var reminder = (attributes.reminder || '').replace(/\./g, '').replace(/\s/g, '');
if (reminder !== '' && !reminder.match(re)) {
return "Enter valid time ie 3:30 pm or 5pm";
}
/* match result
12:00 pm
6pm
6 pm
6:00 pm
3:00pm
5:15am
06:30 pm
06:30pm
06:30 pm
*/
@mjrinker
Copy link

mjrinker commented Aug 5, 2019

Will also match 98:63 pm 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment