fromString

Creates an instance of EmailAddress from the string representation of the specified text, or throws an IllegalArgumentException if the string representation of text doesn't match the default pattern.


Calling from Kotlin

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

val text: Any = "[email protected]"
val isSuccess: Boolean = try {
EmailAddress.fromString(text)
true
} catch (exception: IllegalArgumentException) {
false
}
assertTrue(isSuccess)

Calling from Java

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

final Object text = "[email protected]";
boolean isSuccess;
try {
EmailAddress.fromString(text);
isSuccess = true;
} catch (final IllegalArgumentException exception) {
isSuccess = false;
}
Assertions.assertTrue(isSuccess);

See the fromStringOrNull function for returning null instead of throwing an exception in case of invalid text.


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

Creates an instance of EmailAddress from the string representation of the specified text. Throws an IllegalArgumentException if the string representation of text 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 text: Any = "[email protected]"
val pattern: Any = "^[a-z]+@[a-z]+\\.[a-z]+\$"
val isSuccess: Boolean = try {
EmailAddress.fromString(text, pattern)
true
} catch (exception: IllegalArgumentException) {
false
}
assertTrue(isSuccess)

Calling from Java

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

final Object text = "[email protected]";
final Object pattern = "^[a-z]+@[a-z]+\\.[a-z]+$";
boolean isSuccess;
try {
EmailAddress.fromString(text, pattern);
isSuccess = true;
} catch (final IllegalArgumentException exception) {
isSuccess = false;
}
Assertions.assertTrue(isSuccess);

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