美文网首页
go web接收参数的验证

go web接收参数的验证

作者: 吃猫的鱼0 | 来源:发表于2018-01-16 16:51 被阅读0次

必填字段验证:

len(r.Form["neme"][0])==0
len(r.FormValue("name"))==0

密码的正则验证

m,_=regexp.MatchString(`^([A-Z]|[a-z]|[0-9]|[-=[;,./~!@#$%^*()_+}{:?]){6,20}$`,r.Form.Get("password"))

数字验证:

getint,err:=strconv.Itoa(r.FormValue("name"))
if err!=nil{
//可能不是数字
}

中文验证:

m,_:=regexp.MatchString("^[\\x{4e00}-\\x{9fa5}]+$",r.Form.Get("name"))
if !=m{
//可能不是数字
return false
}

英文验证

m,_:=regexp.MatchString("^[a-zA-z]+$",r.Form.Get("name"))
if !=m{
//可能不是英文
return false
}

电子邮箱验证:

m,_:=regexp.MatchString(`^([\w\.\_]{2,10})@(\w{1,}).([a-z](2,4))$`,r.Form.Get("name"))
if !=m{
//可能不是电子邮箱
return false
}   

手机号码验证:

m,_:=regexp.MatchString(`^(1[3|4|5|8][0-9]\d{4,8})$`,r.Form.Get("name"))
if !=m{
//可能不是手机号码
return false
}   

身份证号码

十八位:

^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$

十五位:

^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}[0-9Xx]$

相关文章

网友评论

      本文标题:go web接收参数的验证

      本文链接:https://www.haomeiwen.com/subject/rgteoxtx.html