main

mattermost/focalboard

Last updated at: 29/12/2023 09:45

email.go

TLDR

This file provides a function for validating an email address.

Methods

IsEmailValid

This method checks if the email provided passes the required structure and length. It takes an email address as a string input and returns a boolean value indicating whether the email address is valid or not.

END

package auth

import "regexp"

var emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")

// IsEmailValid checks if the email provided passes the required structure and length.
func IsEmailValid(e string) bool {
	if len(e) < 3 || len(e) > 254 {
		return false
	}
	return emailRegex.MatchString(e)
}