Skip to content

Commit 7d6236a

Browse files
committed
add updated regex for fqdn
1 parent ee37674 commit 7d6236a

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

baked_in.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,12 +1990,7 @@ func isFQDN(fl FieldLevel) bool {
19901990
return false
19911991
}
19921992

1993-
if val[len(val)-1] == '.' {
1994-
val = val[0 : len(val)-1]
1995-
}
1996-
1997-
return strings.ContainsAny(val, ".") &&
1998-
hostnameRegexRFC952.MatchString(val)
1993+
return fqdnRegexRFC1123.MatchString(val)
19991994
}
20001995

20011996
// IsDir is the validation function for validating if the current field's value is a valid directory.

regexes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const (
3838
sSNRegexString = `^[0-9]{3}[ -]?(0[1-9]|[1-9][0-9])[ -]?([1-9][0-9]{3}|[0-9][1-9][0-9]{2}|[0-9]{2}[1-9][0-9]|[0-9]{3}[1-9])$`
3939
hostnameRegexStringRFC952 = `^[a-zA-Z][a-zA-Z0-9\-\.]+[a-zA-Z0-9]$` // https://tools.ietf.org/html/rfc952
4040
hostnameRegexStringRFC1123 = `^([a-zA-Z0-9]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*?$` // accepts hostname starting with a digit https://tools.ietf.org/html/rfc1123
41+
fqdnRegexStringRFC1123 = `^([a-zA-Z0-9]{1}[a-zA-Z0-9_-]{0,62})(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*?(\.[a-zA-Z]{1}[a-zA-Z0-9]{0,62})\.?$` // same as hostnameRegexStringRFC1123 but must contain a non numerical TLD (possibly ending with '.')
4142
btcAddressRegexString = `^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$` // bitcoin address
4243
btcAddressUpperRegexStringBech32 = `^BC1[02-9AC-HJ-NP-Z]{7,76}$` // bitcoin bech32 address https://en.bitcoin.it/wiki/Bech32
4344
btcAddressLowerRegexStringBech32 = `^bc1[02-9ac-hj-np-z]{7,76}$` // bitcoin bech32 address https://en.bitcoin.it/wiki/Bech32
@@ -86,6 +87,7 @@ var (
8687
sSNRegex = regexp.MustCompile(sSNRegexString)
8788
hostnameRegexRFC952 = regexp.MustCompile(hostnameRegexStringRFC952)
8889
hostnameRegexRFC1123 = regexp.MustCompile(hostnameRegexStringRFC1123)
90+
fqdnRegexRFC1123 = regexp.MustCompile(fqdnRegexStringRFC1123)
8991
btcAddressRegex = regexp.MustCompile(btcAddressRegexString)
9092
btcUpperAddressRegexBech32 = regexp.MustCompile(btcAddressUpperRegexStringBech32)
9193
btcLowerAddressRegexBech32 = regexp.MustCompile(btcAddressLowerRegexStringBech32)

0 commit comments

Comments
 (0)