Verify email format more strictly

This commit is contained in:
Saku Laesvuori 2023-11-01 09:27:55 +02:00
parent 7983f9b187
commit 28af340573
Signed by: slaesvuo
GPG Key ID: 257D284A2A1D3A32
2 changed files with 3 additions and 2 deletions

View File

@ -101,7 +101,8 @@ renderPhoneNumber (PhoneNumber txt) = txt
toPhoneNumber :: Text -> Maybe PhoneNumber
toPhoneNumber txt = do
guard $ not $ T.null txt
guard $ T.all (`elem` ("+ 0123456789" :: [Char])) txt
guard $ T.head txt `elem` ['+','0']
guard $ T.all (`elem` (" 0123456789" :: [Char])) $ T.tail txt
pure $ PhoneNumber txt
instance Eq PhoneNumber where

View File

@ -39,7 +39,7 @@ telephoneField = Field
, fieldView = \id name otherAttributes result isRequired ->
let result' = either (\x -> x) renderPhoneNumber result
in [whamlet|
<input type="tel" id="#{id}" name="#{name}" value="#{result'}" pattern="[+ 0123456789]*" title="Only '+', spaces and numbers are allowed" "*{otherAttributes} :isRequired:required="true">
<input type="tel" id="#{id}" name="#{name}" value="#{result'}" pattern="[+0][ 0123456789]*" title="Only '+', spaces and numbers are allowed" "*{otherAttributes} :isRequired:required="true">
|]
, fieldEnctype = UrlEncoded
}