Skip to content
Snippets Groups Projects

Strip email function

Merged Christel Loftus requested to merge strip_email_function into main
1 file
+ 26
0
Compare changes
  • Side-by-side
  • Inline
+ 26
0
@@ -67,6 +67,32 @@ func ValidateEmailAddress(email string) (string, error) {
return cleanEmail, nil
}
func StripEmail(email string) (strippedEmail string, strippedDomain string) {
// Strip the email address from the + to the @
// Define a regular expression pattern to match the "+" to "@" part
emailPattern := `(\+.*@)`
// Define the regular expression pattern to match the domain part after "@"
domainPattern := `@(.+)`
// Compile the regular expression
emailRegex := regexp.MustCompile(emailPattern)
domainRegex := regexp.MustCompile(domainPattern)
// Replace the matched part with an empty string
strippedEmail = emailRegex.ReplaceAllString(email, "@")
// Find the first match in the email address
match := domainRegex.FindStringSubmatch(email)
// Check if a match was found
if len(match) > 1 {
// The domain part (excluding "@") is in the first capture group (index 1)
strippedDomain = match[1]
}
return strippedEmail, strippedDomain
}
// IsUrlStrict Returns whether a URL is valid in a strict way (Must have scheme and host)
func IsUrlStrict(str string) bool {
u, err := url.Parse(str)
Loading