orNull
Creates an instance of EmailAddress from the specified text, or returns null
if the text doesn't match the default pattern.
Calling from Kotlin
Here's an example of calling this function from Kotlin code:
val text = "contact@kotools.org"
val emailAddress: EmailAddress? = EmailAddress.orNull(text)
assertNotNull(emailAddress)
This function is not available from Java code due to its non-explicit support for nullable types.
See the orThrow function for throwing an exception instead of returning null
in case of invalid text.
Creates an instance of EmailAddress from the specified text. Returns null
if the text doesn't match the specified pattern, or if the pattern doesn't match the default one.
Calling from Kotlin
Here's an example of calling this function from Kotlin code:
val text = "contact@kotools.org"
val pattern = """^[a-z]+@[a-z]+\.[a-z]+$"""
val emailAddress: EmailAddress? = EmailAddress.orNull(text, pattern)
assertNotNull(emailAddress)
This function is not available from Java code due to its non-explicit support for nullable types.
See the orThrow function for throwing an exception instead of returning null
in case of invalid text or pattern.