Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
bef6bca3
Commit
bef6bca3
authored
Jan 05, 2016
by
miraclesu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add function to set validation default messages
parent
f7ef4aa7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
2 deletions
+34
-2
README.md
validation/README.md
+1
-1
validation.go
validation/validation.go
+1
-1
validators.go
validation/validators.go
+32
-0
No files found.
validation/README.md
View file @
bef6bca3
...
...
@@ -41,7 +41,7 @@ Direct Use:
}
}
// or use like this
if v := valid.Max(u.Age, 140); !v.Ok {
if v := valid.Max(u.Age, 140
, "ageMax"
); !v.Ok {
log.Println(v.Error.Key, v.Error.Message)
}
}
...
...
validation/validation.go
View file @
bef6bca3
...
...
@@ -38,7 +38,7 @@
// }
// }
// // or use like this
// if v := valid.Max(u.Age, 140); !v.Ok {
// if v := valid.Max(u.Age, 140
, "ageMax"
); !v.Ok {
// log.Println(v.Error.Key, v.Error.Message)
// }
// }
...
...
validation/validators.go
View file @
bef6bca3
...
...
@@ -46,6 +46,38 @@ var MessageTmpls = map[string]string{
"ZipCode"
:
"Must be valid zipcode"
,
}
// set default messages
// if not set, the default messages are
// "Required": "Can not be empty",
// "Min": "Minimum is %d",
// "Max": "Maximum is %d",
// "Range": "Range is %d to %d",
// "MinSize": "Minimum size is %d",
// "MaxSize": "Maximum size is %d",
// "Length": "Required length is %d",
// "Alpha": "Must be valid alpha characters",
// "Numeric": "Must be valid numeric characters",
// "AlphaNumeric": "Must be valid alpha or numeric characters",
// "Match": "Must match %s",
// "NoMatch": "Must not match %s",
// "AlphaDash": "Must be valid alpha or numeric or dash(-_) characters",
// "Email": "Must be a valid email address",
// "IP": "Must be a valid ip address",
// "Base64": "Must be valid base64 characters",
// "Mobile": "Must be valid mobile number",
// "Tel": "Must be valid telephone number",
// "Phone": "Must be valid telephone or mobile phone number",
// "ZipCode": "Must be valid zipcode",
func
SetDefaultMessage
(
msg
map
[
string
]
string
)
{
if
len
(
msg
)
==
0
{
return
}
for
name
:=
range
msg
{
MessageTmpls
[
name
]
=
msg
[
name
]
}
}
// Validator interface
type
Validator
interface
{
IsSatisfied
(
interface
{})
bool
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment