govalidator
govalidator copied to clipboard
Grouping of characters in "matches" struct tag regex does not work as expected
When validating a US phone number with a regexp, an validation error is returned:
555-234-1234 does not validate as matches(^(1-)?[2-9]{3}-[0-9]{3}-[0-9]{4}$)
However, this regex should match, according to https://play.golang.org/p/G_sqSKwlNw.
The actual code looks like this:
type Phone struct {
Type string `json:"type"`
Number string `json:"number" valid:"matches(^(1-)?[2-9]{3}-[0-9]{3}-[0-9]{4}$)"`
}
I have noticed the same issue. I have been unable to get the matches command to process even the simplest expression like \d. I tried escaping the slash, surrounding with escaped quotes, single quotes, and various other things, but had no success.
Hello guys! I forked this package cause owner disappeared. Hope, he will be back, but it would be easier to merge these changes back if he is back Link to my repo: create issue there and we'll discuss it.