'init'
This commit is contained in:
22
sc-lktx-backend/internal/common/utils/validator.go
Normal file
22
sc-lktx-backend/internal/common/utils/validator.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// 数据校验工具
|
||||
package utils
|
||||
|
||||
import "regexp"
|
||||
|
||||
// ValidatePhone 验证中国大陆手机号(1 开头 + 3-9 + 9 位数字)
|
||||
func ValidatePhone(phone string) bool {
|
||||
matched, _ := regexp.MatchString(`^1[3-9]\d{9}$`, phone)
|
||||
return matched
|
||||
}
|
||||
|
||||
// ValidateIDNumber 验证 18 位身份证号格式
|
||||
func ValidateIDNumber(idNumber string) bool {
|
||||
matched, _ := regexp.MatchString(`^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[\dXx]$`, idNumber)
|
||||
return matched
|
||||
}
|
||||
|
||||
// ValidateLicensePlate 验证中国大陆车牌号
|
||||
func ValidateLicensePlate(plate string) bool {
|
||||
matched, _ := regexp.MatchString(`^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤川青藏琼宁][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$`, plate)
|
||||
return matched
|
||||
}
|
||||
Reference in New Issue
Block a user