HomeRegex Library12-Hour Time with AM/PM Regex
100% Client-Side β€’ 0 B Data Leaves Browser
formatting

12-Hour Time with AM/PM Regex

Validates standard 12-hour time formats with case-insensitive AM or PM indicators.

Regular Expression Pattern:
/^(?:1[0-2]|0?[1-9]):[0-5]\d\s*(?:[AaPp][Mm])$/
Valid Match Example:
11:45 PM
Invalid / Non-Match Example:
13:00 PM

Regex Syntax Breakdown & Explanation

  • β€’(?:1[0-2]|0?[1-9]) : Hours 1 through 12 with optional leading zero
  • β€’: : Time colon delimiter
  • β€’[0-5]\d : Valid minute representation 00-59
  • β€’\s*(?:[AaPp][Mm]) : Optional space followed by AM or PM designation

Implementation in Popular Languages

JavaScript / TypeScript
const regex = /^(?:1[0-2]|0?[1-9]):[0-5]\d\s*(?:[AaPp][Mm])$/;
const isValid = regex.test("11:45 PM");
console.log(isValid); // true
Python (re)
import re

pattern = r"^(?:1[0-2]|0?[1-9]):[0-5]\d\s*(?:[AaPp][Mm])$"
match = re.match(pattern, "11:45 PM")
print(bool(match)) # True
Go (regexp)
package main
import (
  "fmt"
  "regexp"
)

func main() {
  re := regexp.MustCompile(`^(?:1[0-2]|0?[1-9]):[0-5]\d\s*(?:[AaPp][Mm])$`)
  fmt.Println(re.MatchString("11:45 PM"))
}
Frequently Asked Questions

Frequently Asked Questions

Everything you need to know regarding specifications, syntax, and security best practices.

The regular expression pattern is /^(?:1[0-2]|0?[1-9]):[0-5]\d\s*(?:[AaPp][Mm])$/. Validates standard 12-hour time formats with case-insensitive AM or PM indicators.