alberdev / AnimatedField

Animated UITextField with check & filter for default types (email, url, password, price, date...) for iOS written in Swift 5
MIT License
315 stars 48 forks source link

How can i check if a field contains valid data? #1

Closed rursache closed 5 years ago

rursache commented 5 years ago

How can i check if a field contains valid data?

I have a continue button that should only be enabled if all fields are valid, how to check that?

alberdev commented 5 years ago

Hi Radu!

You can use datasource methods to use your own regular expressions for typing and to check field when view did end editing.

func animatedFieldTypingMatches(_ animatedField: AnimatedField) -> String?

use it to send your custom regular expression to check if a character is allowed or not. For example “[A-Z0-9]”, with this you can only type uppercased letters and numbers

func animatedFieldValidationMatches(_ animatedField: AnimatedField) -> String?

use it to check field when did end editing with your own regular expression

Also you can use delegate methods to get AnimatedField text when user ends editing

func animatedFieldDidEndEditing(_ animatedField: AnimatedField)

you can check and enable continue button in this method if animatedField.text is correct

NOTE: In the future, I will add some kind of delegate method or parameter with the result of this check.

Thank you for using AnimatedField!

rursache commented 5 years ago

hey Alberto, thanks for the quick answer!

i am interested to do something like this, using default regex rules from your code

on login button action:

if usernameField.isValid && passwordField.isValid { continue }

i currently cant do that with delegates. isValid is some kind of function that validates that current field on demand

thanks!

alberdev commented 5 years ago

Good idea! I will update AnimatedField with isValid parameter

;)

alberdev commented 5 years ago

Hi Radu! I've updated and released new version 2.0.3 with isValid parameter and new delegate method: didShowAlertMessage. Example is also updated ;)