Allow asterisk in email validation (#5549)

This commit is contained in:
Patrick Honkonen
2025-07-21 11:49:16 -04:00
committed by GitHub
parent e4935318de
commit 17287680d9
2 changed files with 3 additions and 2 deletions

View File

@@ -45,14 +45,14 @@ fun String?.orZeroWidthSpace(): String = this.orNullIfBlank() ?: ZERO_WIDTH_CHAR
*
* This validates that the email is valid by asserting that:
* * The string starts with a string of characters including periods, underscores, percent symbols,
* plus's, minus's, forward slash's, and alphanumeric characters.
* plus's, minus's, forward slash's, asterisks, and alphanumeric characters.
* * Followed by an '@' symbol.
* * Followed by a string of characters including periods, minus's, and alphanumeric characters.
* * Followed by a period.
* * Followed by at least 2 more alphanumeric characters.
*/
fun String.isValidEmail(): Boolean =
this.matches(regex = "^[A-Za-z0-9._%+-/]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$".toRegex())
this.matches(regex = "^[A-Za-z0-9._%+-/*]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$".toRegex())
/**
* Returns `true` if the given [String] is a non-blank, valid URI and `false` otherwise.

View File

@@ -28,6 +28,7 @@ class StringExtensionsTest {
"test.test@test.test.com" to true,
"test/test@test.test.com" to true,
"test.test@test/test.com" to false,
"test*test@test.com" to true,
)
invalidEmails.forEach {
assertEquals(it.first.isValidEmail(), it.second)