Giacomo Balli profile picture
Giacomo Balli
The Mobile Guy

Over two decades of experience at your service.
I help business owners make better decisions.

Let's Chat LinkedIn

Email validation

This code sample will allow you to validate an email in real time, as the user types. The email field will have a red border until a valid email is provided.

<input type="email" onkeyup="checkEmail(this)" placeholder="Your email" />

function checkEmail(el) {
    var val = el.value;
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    if (!re.test(val)) {"2px solid red";
        return false;
    return true;

- add the onkeyup event handler

This snippet focuses on iOS development. Make sure to verify/adapt any vendor prefixes. Back to main listing.

#email, #emailvalidation
Published: Mon, Jan 11 2016 @ 11:52:52
Back to Blog