createOrNull

Creates an email address from the specified text, or returns null 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.createOrNull("[email protected]")
println(address) // [email protected]

Calling from Java

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

final EmailAddress address =
EmailAddress.Companion.createOrNull("[email protected]");
System.out.println(address); // [email protected]

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