emailx

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2019 License: MIT Imports: 4 Imported by: 0

README

emailx

Golang pkg for email validation and normalization.

GoDoc Travis

Email validation

  • Simple email format check (not a complicated regexp, this is why)
  • Resolve the host name
import "github.com/goware/emailx"

func main() {
    err := emailx.Validate("My+Email@wrong.example.com")
    if err != nil {
        fmt.Println("Email is not valid.")

        if err == emailx.ErrInvalidFormat {
            fmt.Println("Wrong format.")
        }

        if err == emailx.ErrUnresolvableHost {
            fmt.Println("Unresolvable host.")
        }
    }
}

Email normalization

import "github.com/goware/emailx"

func main() {
    fmt.Print(emailx.Normalize(" My+Email@example.com. "))
    // Prints my+email@example.com
}

License

Emailx is licensed under the MIT License.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	//ErrInvalidFormat returns when email's format is invalid
	ErrInvalidFormat = errors.New("invalid format")
	//ErrUnresolvableHost returns when validator couldn't resolve email's host
	ErrUnresolvableHost = errors.New("unresolvable host")
)

Functions

func Normalize

func Normalize(email string) string

Normalize normalizes email address.

Example
package main

import (
	"fmt"

	"github.com/goware/emailx"
)

func main() {
	fmt.Println(emailx.Normalize(" Email+Me@example.com. "))
}
Output:

email+me@example.com

func Validate

func Validate(email string) error

Validate checks format of a given email and resolves its host name.

Example
package main

import (
	"fmt"

	"github.com/goware/emailx"
)

func main() {
	err := emailx.Validate("My+Email@wrong.example.com")
	if err != nil {
		fmt.Println("Email is not valid.")

		if err == emailx.ErrInvalidFormat {
			fmt.Println("Wrong format.")
		}

		if err == emailx.ErrUnresolvableHost {
			fmt.Println("Unresolvable host.")
		}
	}
}
Output:

Email is not valid.
Unresolvable host.

func ValidateFast

func ValidateFast(email string) error

ValidateFast checks format of a given email.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL