github.com/songzhibin97/gkit@v1.2.13/sys/stringx/is.go (about) 1 package stringx 2 3 import ( 4 "unicode" 5 ) 6 7 // IsAlpha checks if the string contains only unicode letters. 8 func IsAlpha(s string) bool { 9 if s == "" { 10 return false 11 } 12 for _, v := range s { 13 if !unicode.IsLetter(v) { 14 return false 15 } 16 } 17 return true 18 } 19 20 // IsAlphanumeric checks if the string contains only Unicode letters or digits. 21 func IsAlphanumeric(s string) bool { 22 if s == "" { 23 return false 24 } 25 for _, v := range s { 26 if !isAlphanumeric(v) { 27 return false 28 } 29 } 30 return true 31 } 32 33 // IsNumeric Checks if the string contains only digits. A decimal point is not a digit and returns false. 34 func IsNumeric(s string) bool { 35 if s == "" { 36 return false 37 } 38 for _, v := range s { 39 if !unicode.IsDigit(v) { 40 return false 41 } 42 } 43 return true 44 } 45 46 func isAlphanumeric(v rune) bool { 47 return unicode.IsDigit(v) || unicode.IsLetter(v) 48 }