added string extentions for email and passwords
This commit is contained in:
		
							parent
							
								
									b76852720a
								
							
						
					
					
						commit
						5d92bb09fb
					
				
					 1 changed files with 25 additions and 0 deletions
				
			
		|  | @ -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) | ||||
| } | ||||
		Reference in a new issue
	
	 lbarraga
						lbarraga