fromString

Creates an instance of EmailAddress from the string representation of the specified value, or throws an IllegalArgumentException 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 isSuccess: Boolean = try {
EmailAddress.fromString(value)
true
} catch (exception: IllegalArgumentException) {
false
}
println(isSuccess) // true

Calling from Java

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

final Object value = "[email protected]";
try {
EmailAddress.fromString(value);
System.out.println("success");
} catch (final IllegalArgumentException exception) {
System.out.println("failure");
}
// Output: success

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


fun fromString(value: Any, pattern: Any): EmailAddress

Creates an instance of EmailAddress from the string representation of the specified value. Throws an IllegalArgumentException 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 isSuccess: Boolean = try {
EmailAddress.fromString(value, pattern)
true
} catch (exception: IllegalArgumentException) {
false
}
println(isSuccess) // 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]+$";
try {
EmailAddress.fromString(value, pattern);
System.out.println("success");
} catch (final IllegalArgumentException exception) {
System.out.println("failure");
}
// Output: success

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