Skip to content

Commit e250f2b

Browse files
author
Quentin Brosse
authored
feat(validation): add IsEmail (#242)
1 parent 3cf637f commit e250f2b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

validation/is.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77
)
88

99
var (
10-
isUUIDRegexp = regexp.MustCompile(`[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}`)
10+
isUUIDRegexp = regexp.MustCompile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
1111
isRegionRegex = regexp.MustCompile("^[a-z]{2}-[a-z]{3}$")
1212
isZoneRegex = regexp.MustCompile("^[a-z]{2}-[a-z]{3}-[1-9]$")
1313
isAccessKey = regexp.MustCompile("^SCW[A-Z0-9]{17}$")
14+
isEmailRegexp = regexp.MustCompile("^.+@.+$")
1415
)
1516

1617
// IsUUID returns true if the given string has a valid UUID format.
@@ -48,3 +49,8 @@ func IsURL(s string) bool {
4849
_, err := url.Parse(s)
4950
return err == nil
5051
}
52+
53+
// IsEmail returns true if the given string has an email format.
54+
func IsEmail(v string) bool {
55+
return isEmailRegexp.MatchString(v)
56+
}

0 commit comments

Comments
 (0)