mirror of
https://github.com/element-hq/element-android
synced 2024-11-26 19:35:42 +03:00
Update regex for email address
This commit is contained in:
parent
979324da84
commit
3179dc1400
3 changed files with 14 additions and 3 deletions
|
@ -16,6 +16,11 @@
|
|||
|
||||
package org.matrix.android.sdk.api.extensions
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
const val emailPattern = "^[a-zA-Z0-9_!#\$%&'*+/=?`{|}~^-]+(?:\\.[a-zA-Z0-9_!#\$%&'*+/=?`{|}~^-]+)*@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*\$"
|
||||
val emailAddress: Pattern = Pattern.compile(emailPattern)
|
||||
|
||||
fun CharSequence.ensurePrefix(prefix: CharSequence): CharSequence {
|
||||
return when {
|
||||
startsWith(prefix) -> this
|
||||
|
@ -23,6 +28,11 @@ fun CharSequence.ensurePrefix(prefix: CharSequence): CharSequence {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a CharSequence is an email.
|
||||
*/
|
||||
fun CharSequence.isEmail() = emailAddress.matcher(this).matches()
|
||||
|
||||
/**
|
||||
* Append a new line and then the provided string.
|
||||
*/
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
|
||||
package org.matrix.android.sdk.internal.auth.login
|
||||
|
||||
import android.util.Patterns
|
||||
import org.matrix.android.sdk.api.auth.LoginType
|
||||
import org.matrix.android.sdk.api.auth.login.LoginProfileInfo
|
||||
import org.matrix.android.sdk.api.auth.login.LoginWizard
|
||||
import org.matrix.android.sdk.api.auth.registration.RegisterThreePid
|
||||
import org.matrix.android.sdk.api.extensions.isEmail
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.util.JsonDict
|
||||
import org.matrix.android.sdk.internal.auth.AuthAPI
|
||||
|
@ -59,7 +59,7 @@ internal class DefaultLoginWizard(
|
|||
initialDeviceName: String,
|
||||
deviceId: String?
|
||||
): Session {
|
||||
val loginParams = if (Patterns.EMAIL_ADDRESS.matcher(login).matches()) {
|
||||
val loginParams = if (login.isEmail()) {
|
||||
PasswordLoginParams.thirdPartyIdentifier(
|
||||
medium = ThreePidMedium.EMAIL,
|
||||
address = login,
|
||||
|
|
|
@ -21,6 +21,7 @@ import com.google.i18n.phonenumbers.NumberParseException
|
|||
import com.google.i18n.phonenumbers.PhoneNumberUtil
|
||||
import org.matrix.android.sdk.api.MatrixPatterns
|
||||
import org.matrix.android.sdk.api.extensions.ensurePrefix
|
||||
import org.matrix.android.sdk.api.extensions.isEmail
|
||||
|
||||
fun Boolean.toOnOff() = if (this) "ON" else "OFF"
|
||||
|
||||
|
@ -29,7 +30,7 @@ inline fun <T> T.ooi(block: (T) -> Unit): T = also(block)
|
|||
/**
|
||||
* Check if a CharSequence is an email.
|
||||
*/
|
||||
fun CharSequence.isEmail() = Patterns.EMAIL_ADDRESS.matcher(this).matches()
|
||||
fun CharSequence.isEmail() = this.isEmail()
|
||||
|
||||
fun CharSequence.isMatrixId() = MatrixPatterns.isUserId(this.toString())
|
||||
|
||||
|
|
Loading…
Reference in a new issue