-
Notifications
You must be signed in to change notification settings - Fork 28
/
plate.go
27 lines (22 loc) · 834 Bytes
/
plate.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
26
27
package brdoc
import (
"regexp"
)
// Regexp pattern for license plates patterns.
var (
NationalPlateRegexp = regexp.MustCompile(`^[A-Z]{3}-?\d{4}$`)
MercosulPlateRegexp = regexp.MustCompile(`^[A-Z]{3}\d[A-Z]\d{2}$`)
)
// IsPlate verifies if the given string is a valid license plate.IsPlate
// It can be either in the old national format or the new Mercosul one.
func IsPlate(doc string) bool {
return IsNationalPlate(doc) || IsMercosulPlate(doc)
}
// IsNationalPlate verifies if the given string is a valid license plate in the old national format.
func IsNationalPlate(doc string) bool {
return NationalPlateRegexp.MatchString(doc)
}
// IsMercosulPlate verifies if the given string is a valid license plate in the new Mercosul format.
func IsMercosulPlate(doc string) bool {
return MercosulPlateRegexp.MatchString(doc)
}