I am trying to learn Elm, but the official tutorial got too hard for me.
In the forms tutorial the exercise is to check if the password contains upper case letters, lower case letters and digits.
That is all stuff what I haven’t learned so far…
In other languages I would create a function/method to go through a string and check every single char.
But we haven’t learned for or while loops yet… or even other stuff like Char.
Can someone please help me.
Because I got annoyed of it, I’ve published my own solutions.
They work for Elm 0.19.1.
I have a solution, but it isn’t the one, which was ask in the tutorial, because the tutorial says: “Use the functions from the String module for these exercises!”
I couldn’t do it completely with the String module. I had to import Char, too. And the documentation (https://package.elm-lang.org/packages/elm/core/latest/String#filter) is confusing, too.
It says
filter isDigit "R2-D2" == "22"
, but if I would use it like that, the compiler says “I cannot find aisDigit
variable”It will only work if Char was imported and if it isDigit is definitely coming from char.
Here is my solution:
if String.filter Char.isDigit model.password == "" then div [ style "color" "red"] [text "No numbers"] else if String.filter Char.isUpper model.password == "" then div [ style "color" "red"] [text "No upper"] else if String.filter Char.isLower model.password == "" then div [ style "color" "red"] [text "No lower"]
I hope the language is not as bad as the documentation and the tutorial :(
If someone know the “right” solution. Please post it here :)