Meteor JS: Validating an email quickly

This code can be used in other technologies too.

Example:

mine.html

<input type="text" class="email form-control" 
placeholder="E-Mail" value="{{currentUser.profile.details.email}}">

mine.js

if ( $('.email').val().length > 0 ){
    if(!/^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/.test($('.email').val())) {
        alert("Please enter a valid email.");
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s