A light-weight Scala library for Email validation.
import smail._
val validate: Boolean = Smail.isValid("[email protected]")
val toSmail: Either[SmailError, Smail] = Smail.from("[email protected]")
val unsafeToSmail: Smail = Smail.unsafeFrom("[email protected]")
To enable extension methods, Simply import smail.syntax._
import smail._
import smail.syntax._
val validatedWithSyntax: Boolean = "[email protected]".isValid
val toSmailWithSyntax: Either[SmailError, Smail] = "[email protected]".toSmail
val unsafeToSmailWithSyntax: Smail = "[email protected]".unsafeToSmail
class Smail
is protected with refined type NonEmptyString, which means once you get a valid Smail,
you don't need to worry about empty strings in any part of an Email
import eu.timepit.refined.types.all.NonEmptyString
import smail._
import smail.syntax._
val mySmail: Smail = "[email protected]".unsafeToSmail
val emailName: NonEmptyString = mySmail.name // NonEmptyString("hi_smail")
val emailDomain: NonEmptyString = mySmail.domain // NonEmptyString("gmail")
val emailTld: NonEmptyString = mySmail.tld // NonEmptyString("com")
val emailNameString: String = mySmail.name.value
val emailDomainString: String = mySmail.domain.value
val emailTldString: String = mySmail.tld.value
With EmailAddress
, you can get the structured information for each part of the Email, i.e name(hi_smail)/domain(gmail, hotmail, outlook)/tld(com)
EmailParseError
is a sealed trait with possible pattern matchings:
InvalidUserName
: UserName is not empty but is invalidInvalidDomain
: Domain is not empty but is invalidInvalidTopLevelDomain
: TLD is not empty but is invalidMissingField
: any one or more of Username/Domain/TLD is missing