1
0
Files
omc_api/lib/core/utils/regular/regular.go
2023-10-10 10:56:44 +08:00

55 lines
1.1 KiB
Go
Raw 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 regular
import (
"regexp"
)
// Replace 正则替换
func Replace(originStr, pattern, repStr string) string {
regex := regexp.MustCompile(pattern)
return regex.ReplaceAllString(originStr, repStr)
}
// 判断是否为有效用户名格式
//
// 用户名不能以数字开头可包含大写小写字母数字且不少于5位
func ValidUsername(username string) bool {
if username == "" {
return false
}
pattern := `^[a-zA-Z][a-z0-9A-Z]{5,}`
match, err := regexp.MatchString(pattern, username)
if err != nil {
return false
}
return match
}
// 判断是否为有效手机号格式1开头的11位手机号
func ValidMobile(mobile string) bool {
if mobile == "" {
return false
}
pattern := `^1[3|4|5|6|7|8|9][0-9]\d{8}$`
match, err := regexp.MatchString(pattern, mobile)
if err != nil {
return false
}
return match
}
// 判断是否为http(s)://开头
//
// link 网络链接
func ValidHttp(link string) bool {
if link == "" {
return false
}
pattern := `^http(s)?:\/\/+`
match, err := regexp.MatchString(pattern, link)
if err != nil {
return false
}
return match
}