create

Creates an email address from the specified text, or throws an IllegalArgumentException if the text doesn't match the corresponding regular expression.


Calling from Kotlin

Here's an example of calling this function from Kotlin code:

val address: EmailAddress =
    EmailAddress.create("contact@kotools.org")
println(address) // contact@kotools.org

Calling from Java

Here's an example of calling this function from Java code:

final EmailAddress address =
        EmailAddress.Companion.create("contact@kotools.org");
System.out.println(address); // contact@kotools.org

You can use the EmailAddress.Companion.createOrNull function for returning null instead of throwing an exception in case of invalid text.