Files
gf/util/gvalid/internal/builtin/builtin_qq.go
2022-09-26 22:11:13 +08:00

43 lines
787 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"
)
// RuleQQ implements `qq` rule:
// Tencent QQ number.
//
// Format: qq
type RuleQQ struct{}
func init() {
Register(RuleQQ{})
}
func (r RuleQQ) Name() string {
return "qq"
}
func (r RuleQQ) Message() string {
return "The {field} value `{value}` is not a valid QQ number"
}
func (r RuleQQ) Run(in RunInput) error {
ok := gregex.IsMatchString(
`^[1-9][0-9]{4,}$`,
in.Value.String(),
)
if ok {
return nil
}
return errors.New(in.Message)
}