/
common.go
47 lines (40 loc) · 957 Bytes
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package helper
import (
"fmt"
"github.com/StephanieAgatha/Soraa-Go/model"
"regexp"
"unicode"
)
func IsEmailValid(user model.UserCredentials) error {
// Check if email is valid (e.g., gmail.com)
emailPattern := `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$`
validEmail := regexp.MustCompile(emailPattern)
if !validEmail.MatchString(user.Email) {
return fmt.Errorf("Invalid Email Format")
}
return nil
}
/*
---------PASSWORD REQUIREMENT AREA--------------
*/
func PasswordContainsUppercase(s string) bool {
for _, char := range s {
if unicode.IsUpper(char) {
return true
}
}
return false
}
func PasswordContainsSpecialChar(s string) bool {
// Regular expression to match any special character
re := regexp.MustCompile(`[!@#$%^&*()_+=\[{\]};:'",<.>/?]`)
return re.MatchString(s)
}
func PasswordConstainsOneNumber(s string) bool {
for _, char := range s {
if unicode.IsDigit(char) {
return true
}
}
return false
}