Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us
Notesclub

Email Validation

exercises/email_validation.livemd

Email Validation

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Home Report An Issue RegexCaesar Cypher

Email Validation

Most applications and websites with users have a sign up form with an email input.

Generally, we validate this input to ensure that users enter a valid email.

You are going to build an Email.validate/1 function which checks if an email address is valid or not.

Email.valid?("mail@mail.com")
true

Email.valid?("mail.com")
false

For the sake of this exercise, an email is valid if it is in the format string@string.string. Be aware, this is not sufficient for true email validation where not all characters are allowed.

Hint

Consider using Regex.match/2.

Example Solution

defmodule Email do
  def valid?(email) do
    Regex.match?(~r/\w+\@\w+\.\w+/, email)
  end
end

Implement the Email module as documented.

defmodule Email do
  @moduledoc """
  Documentation for `Email`
  """

  @doc """
  Checks if an email is valid.

  ## Examples

    iex> Email.valid?("mail@mail.com")
    true

    iex> Email.valid?("string@string.string")
    true

    iex> Email.valid?("string")
    false

    iex> Email.valid?(".string")
    false

    iex> Email.valid?("string.string")
    false

    iex> Email.valid?("string@string")
    false

    iex> Email.valid?("string@string.")
    false
  """
  def valid?(email) do
  end
end

Commit Your Progress

DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.

Run git status to ensure there are no undesirable changes. Then run the following in your command line from the curriculum folder to commit your progress.

$ git add .
$ git commit -m "finish Email Validation exercise"
$ git push

We’re proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.

We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.

Navigation

Home Report An Issue RegexCaesar Cypher