Skip to content

Commit

Permalink
feat(validator): 添加 Regexp 用以验证正则表达式是否正确
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed May 27, 2024
1 parent 534bff6 commit 4bb74ee
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions validator/regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ func CNTel(val string) bool { return CNMobile(val) || CNPhone(val) }
func Match(exp *regexp.Regexp) func(string) bool {
return func(val string) bool { return exp.MatchString(val) }
}

// Regexp 是否为一个正确的正则表达式
func Regexp(v string) bool {
_, err := regexp.Compile(v)
return err == nil
}

0 comments on commit 4bb74ee

Please sign in to comment.