init repo
This commit is contained in:
30
pkg/utils/sms.go
Normal file
30
pkg/utils/sms.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package utils
|
||||
|
||||
import "strings"
|
||||
|
||||
// 校验手机号
|
||||
// 规则:
|
||||
// 1. 长度必须为11位
|
||||
// 2. 必须以1开头
|
||||
// 3. 第二位必须是3,4,5,6,7,8,9
|
||||
// 4. 其余必须都是数字
|
||||
func ValidatePhone(phone string) bool {
|
||||
if len(phone) != 11 || !strings.HasPrefix(phone, "1") {
|
||||
return false
|
||||
}
|
||||
|
||||
// 检查第二位
|
||||
secondDigit := phone[1]
|
||||
if secondDigit < '3' || secondDigit > '9' {
|
||||
return false
|
||||
}
|
||||
|
||||
// 检查剩余数字
|
||||
for i := 2; i < len(phone); i++ {
|
||||
if phone[i] < '0' || phone[i] > '9' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user