2020-01-07 17:36:49 +01:00
|
|
|
package txt
|
2019-05-16 08:41:16 +02:00
|
|
|
|
|
|
|
import (
|
2019-12-08 15:05:35 +01:00
|
|
|
"regexp"
|
2019-06-13 20:26:01 +02:00
|
|
|
"strings"
|
2019-05-16 08:41:16 +02:00
|
|
|
)
|
|
|
|
|
2019-12-13 03:07:26 +01:00
|
|
|
var ContainsNumberRegexp = regexp.MustCompile("\\d+")
|
|
|
|
|
2020-01-12 14:00:56 +01:00
|
|
|
// ContainsNumber returns true if string contains a number.
|
2019-12-13 03:07:26 +01:00
|
|
|
func ContainsNumber(s string) bool {
|
|
|
|
return ContainsNumberRegexp.MatchString(s)
|
|
|
|
}
|
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
// Bool casts a string to bool.
|
|
|
|
func Bool(s string) bool {
|
|
|
|
s = strings.TrimSpace(s)
|
|
|
|
|
|
|
|
if s == "" || s == "0" || s == "false" || s == "no" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
2020-06-24 07:38:08 +02:00
|
|
|
|
|
|
|
// ASCII returns true if the string only contains ascii chars without whitespace, numbers, and punctuation marks.
|
|
|
|
func ASCII(s string) bool {
|
|
|
|
for _, r := range s {
|
|
|
|
if (r < 65 || r > 90) && (r < 97 || r > 122) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|