govalidator icon indicating copy to clipboard operation
govalidator copied to clipboard

Grouping of characters in "matches" struct tag regex does not work as expected

Open mwmahlberg opened this issue 8 years ago • 2 comments

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}$)"`
}

mwmahlberg avatar Jun 13 '16 18:06 mwmahlberg

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.

snake14 avatar Oct 28 '16 23:10 snake14

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.

sergeyglazyrindev avatar Oct 17 '21 21:10 sergeyglazyrindev