我应该如何在 Kotlin 多平台移动设备 (KMM) 中验证电子邮件地址?
How should I validate an email address in Kotlin multiplatform mobile(KMM)?
我们应该如何验证 Kotlin 多平台移动 (KMM)?我发现了这个问题,但它使用了 java.util.regex.Pattern 并且对 KMM 没有用:
How should I validate an e-mail address?
您可以使用 Kotlin Regex class 来验证电子邮件地址
/**
* Email address pattern, same as [android.util.Patterns.EMAIL_ADDRESS]
*/
private val emailAddressRegex = Regex(
"[a-zA-Z0-9\+\.\_\%\-\+]{1,256}" +
"\@" +
"[a-zA-Z0-9][a-zA-Z0-9\-]{0,64}" +
"(" +
"\." +
"[a-zA-Z0-9][a-zA-Z0-9\-]{0,25}" +
")+"
)
if (email.matches(emailAddressRegex)){
//Valid email address
}
我们应该如何验证 Kotlin 多平台移动 (KMM)?我发现了这个问题,但它使用了 java.util.regex.Pattern 并且对 KMM 没有用:
How should I validate an e-mail address?
您可以使用 Kotlin Regex class 来验证电子邮件地址
/**
* Email address pattern, same as [android.util.Patterns.EMAIL_ADDRESS]
*/
private val emailAddressRegex = Regex(
"[a-zA-Z0-9\+\.\_\%\-\+]{1,256}" +
"\@" +
"[a-zA-Z0-9][a-zA-Z0-9\-]{0,64}" +
"(" +
"\." +
"[a-zA-Z0-9][a-zA-Z0-9\-]{0,25}" +
")+"
)
if (email.matches(emailAddressRegex)){
//Valid email address
}