orNull

@ExperimentalSince(version = KotoolsTypesVersion.V4_5_3)
fun orNull(text: String): EmailAddress?

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.


@ExperimentalSince(version = KotoolsTypesVersion.V5_0_1)
fun orNull(text: String, regex: EmailAddressRegex): EmailAddress?

Returns an email address from the specified text, or returns null if the text doesn't match the specified regex.


Calling from Kotlin

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

val text = "contact@kotools.org"
val regex: EmailAddressRegex = EmailAddressRegex.alphabetic()
val emailAddress: EmailAddress? = EmailAddress.orNull(text, regex)
val message =
    "'$text' matches the following regular expression: '$regex'."
assertNotNull(emailAddress, message)

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.


@ExperimentalSince(version = KotoolsTypesVersion.V4_5_3)
@DeprecatedAsErrorSince(version = KotoolsTypesVersion.V5_0_1)
fun orNull(text: String, pattern: String): EmailAddress?

Deprecated (with error)

Use the 'EmailAddress.Companion.orNull(String, EmailAddressRegex)' function instead.

Replace with

import org.kotools.types.EmailAddress
import org.kotools.types.EmailAddressRegex
EmailAddressRegex.orNull(pattern)
	?.let { EmailAddress.orNull(text, it) }

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.

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.