Skip to content

Commit a2e4f0c

Browse files
committed
refactor: now, usernames can contain only alphanumeric characters
1 parent 5093bcb commit a2e4f0c

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ module github.com/ralvarezdev/go-validator
22

33
go 1.23.4
44

5-
require github.com/ralvarezdev/go-flags v0.3.2 // indirect
5+
require github.com/ralvarezdev/go-flags v0.3.3 // indirect
66

77
require (
88
github.com/ralvarezdev/go-logger v0.4.6
99
github.com/ralvarezdev/go-reflect v0.2.4
10-
github.com/ralvarezdev/go-strings v0.1.9
10+
github.com/ralvarezdev/go-strings v0.1.11
1111
)

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
github.com/ralvarezdev/go-flags v0.3.2 h1:l3f62CD5NysLAJH5XqSRGiakU/dn4pTGdX4yaBlAmMw=
22
github.com/ralvarezdev/go-flags v0.3.2/go.mod h1:R3yVBYvzwqfOp26LidaiJ/zftVAnPC3pKunVpV/vosE=
3+
github.com/ralvarezdev/go-flags v0.3.3 h1:1NpwdSD+uCMF5NP+szJmq/mXqNFZwrzKAfDNZOznDEQ=
4+
github.com/ralvarezdev/go-flags v0.3.3/go.mod h1:R3yVBYvzwqfOp26LidaiJ/zftVAnPC3pKunVpV/vosE=
35
github.com/ralvarezdev/go-logger v0.4.6 h1:eZalm0WAdNuhzbaVh5D7gC6AFztdpqE/GQfjH2pipyE=
46
github.com/ralvarezdev/go-logger v0.4.6/go.mod h1:zxuMDHqtV2eoJYtmo219lima0ZSk4p/AGj/cCc390P8=
57
github.com/ralvarezdev/go-reflect v0.2.4 h1:PLyzbrdNvUiRzpxSHuI9b7hJEhFes22gjNLZkbjn5AQ=
68
github.com/ralvarezdev/go-reflect v0.2.4/go.mod h1:jv3EqQfUixWtNeJd/Rnzf0IDcYZ1z3GApRdAGQHdHZQ=
7-
github.com/ralvarezdev/go-strings v0.1.9 h1:FyYTJW+EnkWFp5C9GsK6wTt3rXIwPt3mUbsTAFUuAT8=
8-
github.com/ralvarezdev/go-strings v0.1.9/go.mod h1:8sFOqmPJpqzS7bTjf91EzUCITnwpmkfifwY80GxV5r8=
9+
github.com/ralvarezdev/go-strings v0.1.11 h1:3Vla7fGOs+4nyQ3NVaFz+XRP3CTv5JheGt0PXryBcMo=
10+
github.com/ralvarezdev/go-strings v0.1.11/go.mod h1:8sFOqmPJpqzS7bTjf91EzUCITnwpmkfifwY80GxV5r8=

struct/field/username/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ import (
55
)
66

77
var (
8-
ErrFoundWhitespaces = errors.New("username cannot contain whitespaces")
8+
ErrMustBeAlphanumeric = errors.New("username must be have alphanumeric characters")
99
)

struct/mapper/validator/service.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ func (d *DefaultService) Username(
134134
username string,
135135
validations *govalidatormappervalidation.StructValidations,
136136
) {
137-
// Check if the username contains a whitespace
138-
if strings.Contains(username, " ") {
137+
// Check if the username contains non-alphanumeric characters
138+
if gostringscount.Alphanumeric(username) != len(username) {
139139
validations.AddFieldValidationError(
140140
usernameField,
141-
govalidatorfieldusername.ErrFoundWhitespaces,
141+
govalidatorfieldusername.ErrMustBeAlphanumeric,
142142
)
143143
}
144144
}

0 commit comments

Comments
 (0)