forked from rezakhademix/govalidator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mac.go
25 lines (22 loc) · 767 Bytes
/
mac.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package govalidator
const (
// MAC represents rule name which will be used to find the default error message.
MAC = "MAC"
// MACMsg is the default error message format for fields with MAC validation rule.
MACMsg = "%s is not valid"
// MACRegex is the default pattern to validate MAC address field.
MACRegex = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$"
)
// MAC checks the value under validation must match the MACRegex regular expression.
//
// Example:
//
// v := validator.New()
// v.MAC("01:23:45:67:89:A", "MAC", "MAC address is not valid.")
// if v.IsFailed() {
// fmt.Printf("validation errors: %#v\n", v.Errors())
// }
func (v Validator) MAC(s, field, msg string) Validator {
v.RegexMatches(s, MACRegex, field, v.msg(MAC, msg, field))
return v
}