Skip to content

Commit

Permalink
Add validator extension function on TextInputEditText
Browse files Browse the repository at this point in the history
  • Loading branch information
gurleensethi committed Sep 11, 2017
1 parent 7033883 commit fbaeaaa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ class MainActivity : AppCompatActivity() {
var result = editText.validator()
.atLeastOneUpperCase()
.atLeastOneLowerCase()
.maximumLength(3)
.minimumLength(1)
.maximumLength(20)
.minimumLength(5)
.noNumbers()
.addErrorCallback { errorType ->
shortToast("Error ${errorType.toString()}")
}
.addSuccessCallback {
shortToast("Passed")
}
.validate()
}

/*val validator = Validator(passwordEditText.text.toString())
validator.atLeastOneNumber()
.atLeastOneUpperCase()
.minimumLength(8)
.maximumLength(32)
.atLeastOneSpecialCharacter()*/
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.thetechnocafe.gurleensethi.liteutils

import android.support.design.widget.TextInputEditText
import android.widget.EditText

/**
Expand All @@ -10,6 +11,7 @@ import android.widget.EditText
*/

public fun EditText.validator(): Validator = Validator(text.toString())
public fun TextInputEditText.validator(): Validator = Validator(text.toString())

/*
* Class to process all the filters provided by the user
Expand Down Expand Up @@ -203,6 +205,10 @@ class Validator(val text: String) {
}
}

/*
* Enums that serve for identification of error while validation text.
* Every enum is the name of a function with the corresponding validation
* */
enum class ValidationError {
MINIMUM_LENGTH,
MAXIMUM_LENGTH,
Expand Down

0 comments on commit fbaeaaa

Please sign in to comment.