Skip to content

Commit

Permalink
feat: add IsDateString function
Browse files Browse the repository at this point in the history
  • Loading branch information
shintarou37 committed Mar 6, 2024
1 parent a9d515a commit 4d94f08
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ var TagMap = map[string]Validator{
"ISO4217": IsISO4217,
"IMEI": IsIMEI,
"ulid": IsULID,
"date": IsDateString,
}

// ISO3166Entry stores country codes
Expand Down
7 changes: 7 additions & 0 deletions validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1766,3 +1766,10 @@ func (sv stringValues) get(i int) string { return sv[i].String() }
func IsE164(str string) bool {
return rxE164.MatchString(str)
}

// IsDateString checks if a string is in the "YYYY-MM-DD" date format and returns true if valid.
func IsDateString(str string) bool {
layout := "2006-01-02"
_, err := time.Parse(layout, str)
return err == nil
}

0 comments on commit 4d94f08

Please sign in to comment.