Date Regex Go Validator

Search...

⌘K

Date Regex Go Validator

Search...

⌘K


Date Regex Go Validator

Date Regex Go Validator

Validate dates in formats like YYYY-MM-DD, DD/MM/YYYY, or MM-DD-YYYY using this Go Regex Date Validator. Perfect for form inputs, logs, and reports. Test your patterns with our Go Regex Tester, and combine it with tools like Email Regex, Number Regex, and Password Validator for a complete data validation suite.

01/28/2024
Possible security issues
This regex appears to be safe.
Explanation
  • [A-Z]: uppercase letters
  • [a-z]: lowercase letters
  • [0-9]: digits
  • \.: a literal dot
  • +: one or more of the preceding
  • *: zero or more of the preceding
  • ?: optional (zero or one)
  • ^: start of string
  • $: end of string
Match information
Match 1: "01/28/2024" at index 0
Test your APIs today!

Write in plain English — Qodex turns it into secure, ready-to-run tests.

Regular Expression - Documentation

Introduction: What Is Date Regex?

Validating date strings is essential when you’re working with logs, user forms, reports, or any structured input in your Go application. Using regex to validate dates ensures that users enter data in the correct format before it’s saved or processed.

In Go, regex-powered validation works well for basic checks—like format matching for:

  • YYYY-MM-DD (ISO format)

  • DD/MM/YYYY (common in India and Europe)

  • MM-DD-YYYY (common in the US)


Date Regex Patterns

ISO Format (YYYY-MM-DD)

^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$


  • Matches: 2024-12-31

  • Rejects: 2024-13-01, 2024-02-30


DD/MM/YYYY Format


^(0[1-9]|[12]\d|3[01])/(0[1-9]|1[0-2])/\d{4}$


  • Matches: 31/12/2024

  • Rejects: 00/00/2024, 32/01/2024


MM-DD-YYYY Format


^(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])-\d{4}$


  • Matches: 12-31-2024

  • Rejects: 13-01-2024, 00-15-2022


How to Validate Dates Using Regex in Go

Here’s a Go program that checks if a date string is in the correct ISO format (YYYY-MM-DD):


package main

import (
    "fmt"
    "regexp"
)

func isValidDate(date string) bool {
    // Regex for YYYY-MM-DD
    pattern := `^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$`
    regex := regexp.MustCompile(pattern)
    return regex.MatchString(date)
}

func main() {
    dates := []string{"2025-01-30", "2025-13-01", "2024-02-30"}
    for _, date := range dates {
        fmt.Printf("Is '%s' valid? %t\n", date, isValidDate(date))
    }
}


Use Cases of Date Regex Validation

  • Form Input Validation: Check if users entered their birthdate or appointment date in the right format.

  • Data Cleanup: Identify and remove malformed dates in large CSV or JSON datasets.

  • Security: Prevent date injection or malformed string exploits in APIs and user forms.

  • Log Filtering: Parse log entries that contain date strings.


Pro Tips

  • Use regex for format-level validation, but still check if the date actually exists (e.g., Feb 30 isn’t valid).

  • For time formats, extend the regex (e.g., ^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$ for timestamps).

  • Test regex using Go Regex Tester before applying in production.

  • For bulk validation and cleanup, combine this with tools like CSV Cleaner or JSON Validator (coming soon!).


Combine with These Tools

Use this validator with other tools on Qodex for comprehensive input checking:

Frequently asked questions

Does this validator check if the date is real (like Feb 29 on leap years)?×
No, regex only checks format. Logical validation (like real dates) must be done with Go’s time.Parse().
Can this validator be used for timestamps?+
Can it check for future or past dates?+
Does this support multiple formats at once?+
Should I use regex or date parsers?+