mirror of
https://gitee.com/johng/gf
synced 2026-06-18 22:35:54 +08:00
Add more check rules --------- Signed-off-by: yuluo-yx <yuluo08290126@gmail.com> Co-authored-by: hailaz <739476267@qq.com>
40 lines
847 B
Go
40 lines
847 B
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package builtin
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/gogf/gf/v2/text/gregex"
|
|
)
|
|
|
|
// RuleLowercase implements `lowercase` rule:
|
|
// Lowercase alphabetic characters (a-z).
|
|
//
|
|
// Format: lowercase
|
|
type RuleLowercase struct{}
|
|
|
|
func init() {
|
|
Register(RuleLowercase{})
|
|
}
|
|
|
|
func (r RuleLowercase) Name() string {
|
|
return "lowercase"
|
|
}
|
|
|
|
func (r RuleLowercase) Message() string {
|
|
return "The {field} value `{value}` must be lowercase"
|
|
}
|
|
|
|
func (r RuleLowercase) Run(in RunInput) error {
|
|
ok := gregex.IsMatchString(`^[a-z]+$`, in.Value.String())
|
|
if ok {
|
|
return nil
|
|
}
|
|
return errors.New(in.Message)
|
|
}
|