Skip to content
Snippets Groups Projects
Commit 6b2a0a5f authored by Francé Wilke's avatar Francé Wilke
Browse files

Merge branch 'strip_email_function' into 'main'

Strip email function

See merge request !45
parents 856bf0f0 fa40f120
No related branches found
No related tags found
1 merge request!45Strip email function
...@@ -67,6 +67,32 @@ func ValidateEmailAddress(email string) (string, error) { ...@@ -67,6 +67,32 @@ func ValidateEmailAddress(email string) (string, error) {
return cleanEmail, nil 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) // IsUrlStrict Returns whether a URL is valid in a strict way (Must have scheme and host)
func IsUrlStrict(str string) bool { func IsUrlStrict(str string) bool {
u, err := url.Parse(str) u, err := url.Parse(str)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment