| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package utl
- import (
- "regexp"
- )
- var (
- patternEmail string = "^([.]?[a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+$"
- expEmail *regexp.Regexp = regexp.MustCompile(patternEmail)
- patternPhone string = "^(13[0-9]|14[57]|15[0-35-9]|18[0-9]|17[0-9]|16[7]|19[1])\\d{8}$"
- expPhone *regexp.Regexp = regexp.MustCompile(patternPhone)
- patternAlpha string = "^[a-zA-Z]+[a-zA-Z0-9]*$"
- expAlpha *regexp.Regexp = regexp.MustCompile(patternAlpha)
- //patternSafePassword string = ""
- //expSafePassword *regexp.Regexp = regexp.MustCompile(patternSafePassword)
- )
- func IsEmail(email string) bool {
- return expEmail.MatchString(email)
- }
- func IsPhone(phone string) bool {
- return expPhone.MatchString(phone)
- }
- func IsPhoneSimple(phone string) bool {
- if len(phone) != 11 {
- return false
- }
- return phone[0] == 49
- }
- /** begin with alpha, composed with alpha and num */
- func IsAlpha(alpha string) bool {
- return expAlpha.MatchString(alpha)
- }
- func CheckPasswd(passwd string) (lower bool, num bool, upper bool, others bool) {
- lower, upper, num, others = false, false, false, false
- for _, ch := range passwd {
- if ch >= 0x41 && ch <= 0x5A { //A-Z
- upper = true
- } else if ch >= 0x61 && ch <= 0x7A { // a-z
- lower = true
- } else if ch >= 0x30 && ch <= 0x39 {
- num = true
- } else {
- others = true
- }
- }
- return
- }
|