-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(util/gvalid): add more rules: alpha,alpha-dash,alpha-num,lowercase,numeric,uppercase #4601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // 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" | ||
| ) | ||
|
|
||
| // RuleAlpha implements `alpha` rule: | ||
| // Alpha characters (a-z, A-Z). | ||
| // | ||
| // Format: alpha | ||
| type RuleAlpha struct{} | ||
|
|
||
| func init() { | ||
| Register(RuleAlpha{}) | ||
| } | ||
|
|
||
| func (r RuleAlpha) Name() string { | ||
| return "alpha" | ||
| } | ||
|
|
||
| func (r RuleAlpha) Message() string { | ||
| return "The {field} value `{value}` must contain only alphabetic characters" | ||
| } | ||
|
|
||
| func (r RuleAlpha) Run(in RunInput) error { | ||
| ok := gregex.IsMatchString(`^[a-zA-Z]+$`, in.Value.String()) | ||
| if ok { | ||
| return nil | ||
| } | ||
| return errors.New(in.Message) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // 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" | ||
| ) | ||
|
|
||
| // RuleAlphaDash implements `alpha-dash` rule: | ||
| // Alpha-numeric characters, hyphens, and underscores (a-z, A-Z, 0-9, -, _). | ||
| // | ||
| // Format: alpha-dash | ||
| type RuleAlphaDash struct{} | ||
|
|
||
| func init() { | ||
| Register(RuleAlphaDash{}) | ||
| } | ||
|
|
||
| func (r RuleAlphaDash) Name() string { | ||
| return "alpha-dash" | ||
| } | ||
|
|
||
| func (r RuleAlphaDash) Message() string { | ||
| return "The {field} value `{value}` must contain only alpha-numeric characters, hyphens, and underscores" | ||
| } | ||
|
|
||
| func (r RuleAlphaDash) Run(in RunInput) error { | ||
| ok := gregex.IsMatchString(`^[a-zA-Z0-9_\-]+$`, in.Value.String()) | ||
| if ok { | ||
| return nil | ||
| } | ||
| return errors.New(in.Message) | ||
| } | ||
|
yuluo-yx marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // 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" | ||
| ) | ||
|
|
||
| // RuleAlphaNum implements `alpha-num` rule: | ||
| // Alpha-numeric characters (a-z, A-Z, 0-9). | ||
| // | ||
| // Format: alpha-num | ||
| type RuleAlphaNum struct{} | ||
|
|
||
| func init() { | ||
| Register(RuleAlphaNum{}) | ||
| } | ||
|
|
||
| func (r RuleAlphaNum) Name() string { | ||
| return "alpha-num" | ||
| } | ||
|
|
||
| func (r RuleAlphaNum) Message() string { | ||
| return "The {field} value `{value}` must contain only alpha-numeric characters" | ||
| } | ||
|
|
||
| func (r RuleAlphaNum) Run(in RunInput) error { | ||
| ok := gregex.IsMatchString(`^[a-zA-Z0-9]+$`, in.Value.String()) | ||
| if ok { | ||
| return nil | ||
| } | ||
| return errors.New(in.Message) | ||
| } | ||
|
yuluo-yx marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // 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) | ||
| } | ||
|
yuluo-yx marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // 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" | ||
| ) | ||
|
|
||
| // RuleNumeric implements `numeric` rule: | ||
| // Numeric string (0-9). | ||
| // | ||
| // Format: numeric | ||
| type RuleNumeric struct{} | ||
|
|
||
| func init() { | ||
| Register(RuleNumeric{}) | ||
| } | ||
|
|
||
| func (r RuleNumeric) Name() string { | ||
| return "numeric" | ||
| } | ||
|
|
||
| func (r RuleNumeric) Message() string { | ||
| return "The {field} value `{value}` must be numeric" | ||
| } | ||
|
|
||
| func (r RuleNumeric) Run(in RunInput) error { | ||
| ok := gregex.IsMatchString(`^[0-9]+$`, in.Value.String()) | ||
| if ok { | ||
| return nil | ||
| } | ||
| return errors.New(in.Message) | ||
| } | ||
|
yuluo-yx marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // 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" | ||
| ) | ||
|
|
||
| // RuleUppercase implements `uppercase` rule: | ||
| // Uppercase alphabetic characters (A-Z). | ||
| // | ||
| // Format: uppercase | ||
| type RuleUppercase struct{} | ||
|
|
||
| func init() { | ||
| Register(RuleUppercase{}) | ||
| } | ||
|
|
||
| func (r RuleUppercase) Name() string { | ||
| return "uppercase" | ||
| } | ||
|
|
||
| func (r RuleUppercase) Message() string { | ||
| return "The {field} value `{value}` must be uppercase" | ||
| } | ||
|
|
||
| func (r RuleUppercase) Run(in RunInput) error { | ||
| ok := gregex.IsMatchString(`^[A-Z]+$`, in.Value.String()) | ||
| if ok { | ||
| return nil | ||
| } | ||
| return errors.New(in.Message) | ||
| } | ||
|
yuluo-yx marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.