Skip to content

Commit dbfcad2

Browse files
author
Dean Karn
authored
Merge pull request #583 from metalinspired/master
Add validators that check if string does not start/end with supplied parameter
2 parents 07f2314 + f3b347c commit dbfcad2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

baked_in.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ var (
120120
"excludesrune": excludesRune,
121121
"startswith": startsWith,
122122
"endswith": endsWith,
123+
"startsnotwith": startsNotWith,
124+
"endsnotwith": endsNotWith,
123125
"isbn": isISBN,
124126
"isbn10": isISBN10,
125127
"isbn13": isISBN13,
@@ -690,6 +692,16 @@ func endsWith(fl FieldLevel) bool {
690692
return strings.HasSuffix(fl.Field().String(), fl.Param())
691693
}
692694

695+
// StartsNotWith is the validation function for validating that the field's value does not start with the text specified within the param.
696+
func startsNotWith(fl FieldLevel) bool {
697+
return !startsWith(fl)
698+
}
699+
700+
// EndsNotWith is the validation function for validating that the field's value does not end with the text specified within the param.
701+
func endsNotWith(fl FieldLevel) bool {
702+
return !endsWith(fl)
703+
}
704+
693705
// FieldContains is the validation function for validating if the current field's value contains the field specified by the param's value.
694706
func fieldContains(fl FieldLevel) bool {
695707
field := fl.Field()

doc.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,18 @@ This validates that a string value ends with the supplied string value
814814
815815
Usage: endswith=goodbye
816816
817+
Does Not Start With
818+
819+
This validates that a string value does not start with the supplied string value
820+
821+
Usage: startsnotwith=hello
822+
823+
Does Not End With
824+
825+
This validates that a string value does not end with the supplied string value
826+
827+
Usage: endsnotwith=goodbye
828+
817829
International Standard Book Number
818830
819831
This validates that a string value contains a valid isbn10 or isbn13 value.

0 commit comments

Comments
 (0)