{-# LANGUAGE TypeApplications #-}
module Main where
import Data.Char (isAlphaNum, isSpace)
maxLength :: String -> Maybe String
maxLength "" = Nothing
maxLength xs =
case (length xs > 20) of
True -> Nothing
False -> Just xs
allAlpha :: String -> Maybe String
allAlpha "" = Nothing
allAlpha xs =
case (all isAlphaNum xs) of
False -> Nothing
True -> Just xs
stripSpace :: String -> Maybe String
stripSpace "" = Nothing
stripSpace (x : xs) =
case (isSpace x) of
True -> stripSpace xs
False -> Just (x : xs)
validatePassword :: String -> Maybe String
validatePassword password =
stripSpace password >>= allAlpha >>= maxLength
main :: IO ()
main = do
putStrLn "Please enter a password"
password <- getLine
print (validatePassword password)
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (1)
If you're so inclined, you can also write validatePassword as,
Main advantage being, you can separate out your list of validators and, for example, reuse them elsewhere...