Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions util/gvalid/internal/builtin/builtin_alpha.go
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)
}
Comment thread
yuluo-yx marked this conversation as resolved.
39 changes: 39 additions & 0 deletions util/gvalid/internal/builtin/builtin_alpha_dash.go
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)
}
Comment thread
yuluo-yx marked this conversation as resolved.
39 changes: 39 additions & 0 deletions util/gvalid/internal/builtin/builtin_alpha_num.go
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)
}
Comment thread
yuluo-yx marked this conversation as resolved.
39 changes: 39 additions & 0 deletions util/gvalid/internal/builtin/builtin_lowercase.go
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)
}
Comment thread
yuluo-yx marked this conversation as resolved.
39 changes: 39 additions & 0 deletions util/gvalid/internal/builtin/builtin_numeric.go
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)
}
Comment thread
yuluo-yx marked this conversation as resolved.
39 changes: 39 additions & 0 deletions util/gvalid/internal/builtin/builtin_uppercase.go
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)
}
Comment thread
yuluo-yx marked this conversation as resolved.
Loading