validating email address without regular expression in javascript


Here in this post we will validate email address without regular expression, though we can perform a very basic validation of email address with JavaScript by implementing the following three email validation rules.

1. The email address must have @ character
2. The email address must have .(dot) character
3. There must be at lease 2 characters between @ and .(dot)

JavaScript Function for this

    function validate(){
        var t=document.getElementById('email');
        var x=t.value.indexOf('@');
        var y=t.value.lastIndexOf('.');

        if(x==-1 || y==-1 || (x+2)>=y){
            alert('Email address is not valid');
            alert('Email is ok');


<title>Email validation with JavaScript</title>
     <input type="text" name="email" id="email" />
     <input type="button" value="Validate" onclick="validate()" />

There are many techniques of validating email address, each validation method has its own pros and cons. The above method doesn't require understanding of regular expressions