github.com/gogf/gf/v2@v2.7.4/util/gvalid/internal/builtin/builtin_password.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package builtin 8 9 import ( 10 "errors" 11 12 "github.com/gogf/gf/v2/text/gregex" 13 ) 14 15 // RulePassword implements `password` rule: 16 // Universal password format rule1: 17 // Containing any visible chars, length between 6 and 18. 18 // 19 // Format: password 20 type RulePassword struct{} 21 22 func init() { 23 Register(RulePassword{}) 24 } 25 26 func (r RulePassword) Name() string { 27 return "password" 28 } 29 30 func (r RulePassword) Message() string { 31 return "The {field} value `{value}` is not a valid password format" 32 } 33 34 func (r RulePassword) Run(in RunInput) error { 35 if !gregex.IsMatchString(`^[\w\S]{6,18}$`, in.Value.String()) { 36 return errors.New(in.Message) 37 } 38 return nil 39 }