added string extentions for email and passwords

This commit is contained in:
lbarraga 2023-04-08 17:32:40 +02:00
parent b76852720a
commit 5d92bb09fb

View file

@ -0,0 +1,25 @@
package be.ugent.sel.studeez.common.ext
import android.util.Patterns
import java.util.regex.Pattern
private const val MIN_PASS_LENGTH = 6
private const val PASS_PATTERN = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=\\S+$).{4,}$"
fun String.isValidEmail(): Boolean {
return this.isNotBlank() && Patterns.EMAIL_ADDRESS.matcher(this).matches()
}
fun String.isValidPassword(): Boolean {
return this.isNotBlank() &&
this.length >= MIN_PASS_LENGTH &&
Pattern.compile(PASS_PATTERN).matcher(this).matches()
}
fun String.passwordMatches(repeated: String): Boolean {
return this == repeated
}
fun String.idFromParameter(): String {
return this.substring(1, this.length - 1)
}