Skip to content

Commit

Permalink
update validate email 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fchrgrib committed Jun 16, 2023
1 parent 7ec6e3c commit d0cc4b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion handlers/authandlers/Register.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func CreateUser(user models.User) error {
}

//validating email is the string is email or not
if !validation.ValidateEmail(user.Email) {
if !validation.ValidateUserOtherEmail(user.Email) {
return errors.New("email is invalid")
}

Expand Down
13 changes: 12 additions & 1 deletion libs/utils/validation/EmailValidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"regexp"
)

func ValidateEmail(e string) bool {
func ValidateUserOtherEmail(e string) bool {

if govalidator.IsNull(e) {
return false
Expand All @@ -24,3 +24,14 @@ func ValidateEmail(e string) bool {

return true
}

func ValidateEmail(e string) bool {
if govalidator.IsNull(e) {
return false
}
if !govalidator.IsEmail(e) {
return false
}

return true
}
8 changes: 4 additions & 4 deletions testing/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ import (
)

func TestEmailValidation(t *testing.T) {
result := validation.ValidateEmail("[email protected]")
result := validation.ValidateUserOtherEmail("[email protected]")
expected := true
if result != expected {
t.Errorf("checking email isn't valid")
}

result = validation.ValidateEmail("[email protected]")
result = validation.ValidateUserOtherEmail("[email protected]")
expected = false
if result != expected {
t.Errorf("checking email that not contain @wallpaper.Collect.app isn't valid")
}

result = validation.ValidateEmail("@wallpaper.Collect.app")
result = validation.ValidateUserOtherEmail("@wallpaper.Collect.app")
expected = false
if result != expected {
t.Errorf("checking validation before @ isn't valid")
}

result = validation.ValidateEmail("")
result = validation.ValidateUserOtherEmail("")
expected = false
if result != expected {
t.Errorf("checking isNull isn't valid")
Expand Down

3 comments on commit d0cc4b5

@vercel
Copy link

@vercel vercel bot commented on d0cc4b5 Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on d0cc4b5 Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on d0cc4b5 Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.