golang实现验证电子信箱和手机格式合法性(正则表达式)
By admin
- One minute read - 56 words邮箱验证
func checkEmail(email string) (b bool) {
if m, _ := regexp.MatchString("^([a-zA-Z0-9\_-])+@([a-zA-Z0-9\_-])+(.[a-zA-Z0-9_-])+", email); !m {
return false
}
return true
}
手机验证
package main
import (
"regexp"
)
const (
regular = "^(13[0-9]|14[57]|15[0-35-9]|18[07-9])\\d{8}$"
)
func validate(mobileNum string) bool {
reg := regexp.MustCompile(regular)
return reg.MatchString(mobileNum)
}
func main() {
if validate("13888888888") {
println("是手机号")
return
}
println("不是手机号")
}