In this article I will explain with an example, how to perform Email validation without using Regular Expression (Regex) in JavaScript.
This article will illustrate how to validate Email Address without using Regular Expression (Regex) i.e. by making use of String operations and checking the various requirements for a valid Email Address using JavaScript.
 
 
HTML Markup
The following HTML Markup consists of an HTML TextBox, SPAN element and a Button. The Button has been assigned an OnClick event handler which calls the ValidateEmail JavaScript function.
<input type="text" id="txtEmail" />
<span id="lblError" style="color:red"></span>
<br />
<br />
<input type="button" id="btnValidate" value="Submit" onclick="ValidateEmail()" />
 
 
JavaScript function to perform Email validation without using Regular Expression
When the Submit Button is clicked, the Email Address in the TextBox will be validated using JavaScript without using Regular Expression (Regex) and if the Email Address is invalid, the error message will be displayed next to the TextBox.
The Email Address validation is performed using the IsValidEmail JavaScript function. Inside the IsValidEmailJavaScript function, the validation is performed in following steps.
1. Email Address length validation.
2. Email Address must contain @ character.
3. Email Address must contain minimum 1 and maximum 2 Dots after @ character and there should minimum one non-special character between @ and Dot.
4. Dot must not be the last character in the Email Address and Dots cannot be in consecutive repetition.
<script type="text/javascript">
    function IsValidEmail(email) {
        //Check minimum valid length of an Email.
        if (email.length <= 2) {
            return false;
        }
        //If whether email has @ character.
        if (email.indexOf("@") == -1) {
            return false;
        }
 
        var parts = email.split("@");
        var dot = parts[1].indexOf(".");
        var len = parts[1].length;
        var dotSplits = parts[1].split(".");
        var dotCount = dotSplits.length - 1;
 
 
        //Check whether Dot is present, and that too minimum 1 character after @.
        if (dot == -1 || dot < 2 || dotCount > 2) {
            return false;
        }
 
        //Check whether Dot is not the last character and dots are not repeated.
        for (var i = 0; i < dotSplits.length; i++) {
            if (dotSplits[i].length == 0) {
                return false;
            }
        }
 
        return true;
    };
    function ValidateEmail() {
        var email = document.getElementById("txtEmail").value;
        var lblError = document.getElementById("lblError");
        lblError.innerHTML = "";
        if (!IsValidEmail(email)) {
            lblError.innerHTML = "Invalid email address.";
        }
    }
</script>
 
 
Screenshot
Email validation without using Regular Expression in JavaScript
 
 
Browser Compatibility

The above code has been tested in the following browsers.

Internet Explorer  FireFox  Chrome  Safari  Opera 

* All browser logos displayed above are property of their respective owners.

 
 
Demo
 
 
Downloads