Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Use Regex to Validate an Email in Elm

    Enrico BuonannoEnrico Buonanno

    The Regex package provides functionality required to carry out regex-based validation.

    elmElm
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    Instructor: 00:01 At the moment, our validation for emails is very simplistic. It just checks that the @ is there. If we want a more realistic Regex-based implementation, then we need to improve that. To do this, first we need to import the Regex module, and then let me change the implementation.

    00:21 I create a regular expression. The Regex function converts a string to a regular expression, and I've just copied in a suitable string. Then we can make this case insensitive with the caseInsensitive function. Now, rather than string.contains, we can say regex.contains, using our Regex and given value.

    00:52 I have a typo here. Now, let me check that it works as intended. If I just type @, this will have passed validation in the previous implementation, but now it fails. If I type a valid email, you can see this now passes validation.

    Discuss

    Discuss