orNull

Returns a regular expression for validating email addresses from the specified pattern, or returns null if the pattern doesn't match the default one.


Calling from Kotlin

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

val pattern = """^[a-z]+@[a-z]+\.[a-z]+$"""
val regex: EmailAddressRegex? = EmailAddressRegex.orNull(pattern)
val message = "'$pattern' is valid for validating email addresses."
assertNotNull(regex, 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 in case of invalid pattern instead of returning null.