Code hygiene

- Minor performance improve for FQDN validation
- Fix typo in documentation
- Simplified hostname regex
pull/298/head
Bruno Lorenz 7 years ago
parent 1669b6e0ee
commit dbd50b343f
  1. 4
      baked_in.go
  2. 2
      doc.go
  3. 2
      regexes.go

@ -1491,6 +1491,6 @@ func isFQDN(fl FieldLevel) bool {
val = val[0 : len(val)-1] val = val[0 : len(val)-1]
} }
return hostnameRegex.MatchString(val) && return (strings.IndexAny(val, ".") > -1) &&
(strings.IndexAny(val, ".") > -1) hostnameRegex.MatchString(val)
} }

@ -796,7 +796,7 @@ Note: See Go's ParseMAC for accepted formats and types:
Hostname Hostname
This validates that a stringa value is a valid Hostname This validates that a string value is a valid Hostname
Usage: hostname Usage: hostname

@ -30,7 +30,7 @@ const (
latitudeRegexString = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$" latitudeRegexString = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$"
longitudeRegexString = "^[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$" longitudeRegexString = "^[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$"
sSNRegexString = `^\d{3}[- ]?\d{2}[- ]?\d{4}$` sSNRegexString = `^\d{3}[- ]?\d{2}[- ]?\d{4}$`
hostnameRegexString = `^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$` hostnameRegexString = `^[a-zA-Z][a-zA-Z0-9\-\.]+[a-z-Az0-9]$`
) )
var ( var (

Loading…
Cancel
Save