Created
August 7, 2019 14:50
-
-
Save zacck-zz/0de919fce55d17d237b2c234b18aa2f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EnteredAccount str -> | |
let | |
newProblems = | |
model.problems | |
|> List.filter (\p -> | |
case p of | |
InvalidEntry Account _ -> | |
False | |
_ -> True | |
) | |
isLowerThan7 : Char -> Bool | |
isLowerThan7 c = | |
let | |
charInt : Int | |
charInt = | |
c | |
|> String.fromChar | |
|> String.toInt | |
|> Maybe.withDefault 0 | |
in | |
if compare charInt 7 == Basics.LT then | |
True | |
else | |
False | |
isValidAlphaNum : Char -> Bool | |
isValidAlphaNum c = | |
(Char.isUpper c || Char.isLower c || Char.isDigit c) && isLowerThan7 c | |
accountErrors : List Problem | |
accountErrors = | |
let | |
errorString : ValidationError -> String | |
errorString verror = | |
validationErrorToString shared verror | |
accountValidator = | |
newValidator "" (\a -> Just a) True | |
<| custom (\st -> String.length st > 12) (\_ -> errorString AccountTooShort) | |
<| custom (\st -> String.length st < 12) (\_ -> errorString AccountTooLong) | |
<| custom (\st -> String.all isValidAlphaNum st) (\_ -> errorString AccountInvalidChars) [] | |
accountValidationErrors = | |
accountValidator | |
|> updateInput str | |
|> validate | |
|> listErrors shared.translations | |
in | |
accountValidationErrors | |
|> List.map (\e -> InvalidEntry Account e) | |
_ = Debug.log "len" (String.length str) | |
newForm = | |
{ form | account = str } | |
in | |
{ model | |
| form = newForm | |
, problems = accountErrors ++ newProblems | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment