Files
huangjin fe3ad20fe2 'init'
2026-06-29 17:34:59 +08:00

23 lines
816 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 数据校验工具
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
}