Cookies management by TermsFeed Cookie Consent

📨 Validate an email address in Go


An email address in Golang can be validated using the standard library function mail.ParseAddress. This function parses an RFC 5322 address, but by using it appropriately, we can also check if a string is a valid email address and get it from the "name <local-part@domain>" format.

package main

import (

func validMailAddress(address string) (string, bool) {
    addr, err := mail.ParseAddress(address)
    if err != nil {
        return "", false
    return addr.Address, true

var addresses = []string{
    "Gopher <>",

func main() {
    for _, a := range addresses {
        if addr, ok := validMailAddress(a); ok {
            fmt.Printf("value: %-30s valid email: %-10t address: %s\n", a, ok, addr)
        } else {
            fmt.Printf("value: %-30s valid email: %-10t\n", a, ok)


value:                  valid email: true       address:
value: Gopher <>      valid email: true       address:
value: example                        valid email: false     

Thank you for being on our site 😊. If you like our tutorials and examples, please consider supporting us with a cup of coffee and we'll turn it into more great Go examples.

Have a great day!

Buy Me A Coffee