Created
October 6, 2022 17:44
-
-
Save clarkritchie/9060520f9721378344efdfa8fc5d21cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// You can edit this code! | |
// Click here and start typing. | |
package main | |
import ( | |
"fmt" | |
"net/mail" | |
"strings" | |
) | |
func emailValid(email string) bool { | |
_, err := mail.ParseAddress(email) | |
return err == nil | |
} | |
func main() { | |
for _, email := range []string{ | |
"good@exmaple.com", | |
"bad-example", | |
"foo bar@bar.com ", | |
} { | |
fmt.Printf("%18s valid: %t\n", email, emailValid(email)) | |
} | |
var data = map[string]interface{}{ | |
"event": "something", | |
"customer_properties": map[string]interface{}{ | |
"$email": strings.TrimSpace("hello@clark.co"), | |
}, | |
"properties": map[string]interface{}{ | |
"lang": "en", | |
}, | |
} | |
cprops, _ := data["customer_properties"].(map[string]interface{}) | |
email, _ := cprops["$email"].(string) | |
if emailValid(email) { | |
fmt.Printf("email '%s' is valid\n", email) | |
} else { | |
fmt.Printf("email '%s' is NOT valid\n", email) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment