@username_regex ~r/^[[:alnum:]]+(\.[[:alnum:]]+)?$/
@mail_regex ~r/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/
defp check_username_or_email_and_password_on_blink(username, email, password) do
IO.inspect(username)
IO.inspect(email)
IO.inspect(password)
cond do
username == nil && email == nil && password == nil ->
"Please type username, email and password"
username == nil && email == nil && String.length(password) <= 2 ->
"Please type username and email. Password is shorter"
username == nil && email == nil && String.length(password) >= 11 ->
"Please type username and email. Password is longer"
username == nil && email == nil && password != nil ->
"Please type username, email."
username != nil && String.length(username) <= 2 && email == nil &&
String.length(password) <= 2 ->
"Username shorter. Password shorter"
username != nil && String.length(username) >= 11 && email == nil &&
String.length(password) <= 2 ->
"Username longer. Password shorter"
username != nil && String.length(username) >= 11 && email == nil &&
String.length(password) >= 11 ->
"Username longer. Password longer"
username == nil && String.length(email) <= 2 && String.length(password) <= 2 ->
"Email shorter. Password shorter"
username == nil && String.length(email) >= 11 && String.length(password) <= 2 ->
"Email longer. Password shorter"
username == nil && String.length(email) >= 11 && String.length(password) >= 11 ->
"Email longer. Password longer"
username != nil && Regex.match?(@username_regex, username) == false && email == nil &&
String.length(password) <= 2 ->
"Wrong username format. Password shorter"
username != nil && Regex.match?(@username_regex, username) == false && email == nil &&
String.length(password) >= 11 ->
"Wrong username format. Password longer"
username != nil && Regex.match?(@username_regex, username) == false && email == nil &&
String.length(password) >= 3 && String.length(password) <= 10 ->
"Wrong username format"
email != nil && Regex.match?(@mail_regex, email) == false && username == nil &&
String.length(password) <= 2 ->
"Wrong email format. Password shorter"
email != nil && Regex.match?(@mail_regex, email) == false && username == nil &&
String.length(password) >= 11 ->
"Wrong email format. Password longer"
email != nil && Regex.match?(@mail_regex, email) == false && username == nil &&
String.length(password) >= 3 && String.length(password) <= 10 ->
"Wrong email format"
password == nil ->
"Please type password"
String.length(password) <= 2 ->
"Password shorter"
String.length(password) >= 11 ->
"Password longer"
username != nil && Regex.match?(@username_regex, username) == true && email == nil &&
String.length(password) >= 3 && String.length(password) <= 10 ->
%{username: username}
username == nil && Regex.match?(@mail_regex, email) == true && String.length(password) >= 3 &&
String.length(password) <= 10 ->
%{email: email}
true ->
:error
end
end
на паттерн-матчинг надо все переделать
C case пробовал такая же проблема.
условия можно прямо в шапке проверять. и работает быстрее
У тебя ограничение на максимальную длину пароля?..
Да, но это условное ограничение.
Обсуждают сегодня