Files
gf/util/gvalid/internal/builtin/builtin_phone_loose.go
shown 40f4d9f8ec chore: translte zh comment to en (#4591)
AS TITLE

---------

Signed-off-by: yuluo-yx <yuluo08290126@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-09 14:27:28 +08:00

46 lines
1.1 KiB
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"
)
// RulePhoneLoose implements `phone-loose` rule:
// Loose mobile phone number verification.
// As long as the 11 digits numbers beginning with
// 13, 14, 15, 16, 17, 18, 19 can pass the verification
// (Any 11-digit numbers starting with 13, 14, 15, 16, 17, 18, 19 can pass the validation).
//
// Format: phone-loose
type RulePhoneLoose struct{}
func init() {
Register(RulePhoneLoose{})
}
func (r RulePhoneLoose) Name() string {
return "phone-loose"
}
func (r RulePhoneLoose) Message() string {
return "The {field} value `{value}` is not a valid phone number"
}
func (r RulePhoneLoose) Run(in RunInput) error {
ok := gregex.IsMatchString(
`^1(3|4|5|6|7|8|9)\d{9}$`,
in.Value.String(),
)
if ok {
return nil
}
return errors.New(in.Message)
}