go-ozzo / ozzo-validation

An idiomatic Go (golang) validation package. Supports configurable and extensible validation rules (validators) using normal language constructs instead of error-prone struct tags.
MIT License
3.73k stars 224 forks source link

E164 compliance regex is wrong must not accept phone numbers without "+" at the beginning #195

Open Wigwamwam opened 4 weeks ago

Wigwamwam commented 4 weeks ago

Hey, noticed that your source to the stack overflow regex reference for e164 compliant phoneNumbers is incorrect - https://stackoverflow.com/a/23299989. In the comments of the thread it states:

The "+" is not optional in E.164 for services like Twilio, so remove the ? after the + ^\+[1-9]\d{1,14}$ – 

This is backed up by the Twilio page: https://www.twilio.com/docs/glossary/what-e164 - they make reference to the correct regex: ^\+[1-9]\d{1,14}$

Therefore the regex must be the following:

// E164 regex source: https://www.twilio.com/docs/glossary/what-e164
reE164 = regexp.MustCompile(`^\+[1-9]\d{1,14}$`)