orThrow

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


Calling from Kotlin

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

EmailAddressRegex.orThrow("""^[a-z]+@[a-z]+\.[a-z]+$""")

Calling from Java

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

EmailAddressRegex.orThrow("^\\S+@\\S+\\.\\S+$");

See the orNull function for returning null in case of invalid pattern instead of throwing an exception.