accept 0x(0X) start in 'hexadecimal' tag (#620)

* accept hexadecimal which starts with 0x(0X) optionally
pull/671/head
Brandon Lee 4 years ago committed by GitHub
parent 4407f4dea0
commit 704a814277
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      regexes.go
  2. 8
      validator_test.go

@ -9,7 +9,7 @@ const (
alphaUnicodeNumericRegexString = "^[\\p{L}\\p{N}]+$"
numericRegexString = "^[-+]?[0-9]+(?:\\.[0-9]+)?$"
numberRegexString = "^[0-9]+$"
hexadecimalRegexString = "^[0-9a-fA-F]+$"
hexadecimalRegexString = "^(0[xX])?[0-9a-fA-F]+$"
hexcolorRegexString = "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"
rgbRegexString = "^rgb\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*\\)$"
rgbaRegexString = "^rgba\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*,\\s*(?:(?:0.[1-9]*)|[01])\\s*\\)$"

@ -7765,6 +7765,14 @@ func TestHexadecimal(t *testing.T) {
errs := validate.Var(s, "hexadecimal")
Equal(t, errs, nil)
s = "0xff0044"
errs = validate.Var(s, "hexadecimal")
Equal(t, errs, nil)
s = "0Xff0044"
errs = validate.Var(s, "hexadecimal")
Equal(t, errs, nil)
s = "abcdefg"
errs = validate.Var(s, "hexadecimal")
NotEqual(t, errs, nil)

Loading…
Cancel
Save