fromStringOrNull

Creates an instance of EmailAddress from the string representation of the specified value, or returns null if the string representation of value doesn't match the default pattern.


Calling from Kotlin

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

val value: Any = "[email protected]"
val address: EmailAddress? = EmailAddress.fromStringOrNull(value)
println(address != null) // true

Calling from Java

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

final Object value = "[email protected]";
final EmailAddress address = EmailAddress.fromStringOrNull(value);
System.out.println(address != null); // true

You can use the fromString function for throwing an exception instead of returning null in case of invalid value.


Creates an instance of EmailAddress from the string representation of the specified value. Returns null if the string representation of value doesn't match the string representation of the specified pattern, or if the string representation of pattern doesn't match the default pattern.


Calling from Kotlin

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

val value: Any = "[email protected]"
val pattern: Any = "^[a-z]+@[a-z]+\\.[a-z]+\$"
val address: EmailAddress? =
EmailAddress.fromStringOrNull(value, pattern)
println(address != null) // true

Calling from Java

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

final Object value = "[email protected]";
final Object pattern = "^[a-z]+@[a-z]+\\.[a-z]+$";
final EmailAddress address =
EmailAddress.fromStringOrNull(value, pattern);
System.out.println(address != null); // true

You can use the fromString function for throwing an exception instead of returning null in case of invalid value or pattern.