User Id :    Password :      New Member   Forgot Password  
Topic: How to check the validation on email by JavaScript?
Anamika singh
23 Nov 2010 at 03:11 AM

How to check the validation on email by JavaScript?

Re: How to check the validation on email by JavaScript?
Gaurav
16 Dec 2010 at 02:26 AM
Function echeck is used to verify if the given value is a possible valid email address. This function thus simply makes sure the email address has one (@), atleast one (.). It also makes sure that there are no spaces, extra '@'s or a (.) just before or after the @. It also makes sure that there is atleast one (.) after the @.

Remember that the position starts counting at 0, so if indexOf returns zero, it means your character or string begins at the 1st character. Also, indexOf has a useful return value of -1 if the character or string you searched for is not contained within the string. And finally, if the character or string you search for occurs more than once, indexOf returns only the first appearance of your character or string.

function echeck(str) {

        var at="@"
        var dot="."
        var lat=str.indexOf(at)
        var lstr=str.length
        var ldot=str.indexOf(dot)
        if (str.indexOf(at)==-1){
           alert("Invalid E-mail ID")
           return false
        }

        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
           alert("Invalid E-mail ID")
           return false
        }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
            alert("Invalid E-mail ID")
            return false
        }

         if (str.indexOf(at,(lat+1))!=-1){
            alert("Invalid E-mail ID")
            return false
         }

         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
            alert("Invalid E-mail ID")
            return false
         }

         if (str.indexOf(dot,(lat+2))==-1){
            alert("Invalid E-mail ID")
            return false
         }

         if (str.indexOf(" ")!=-1){
            alert("Invalid E-mail ID")
            return false
         }

          return true                   
    }
Total Replies: 1
 
Featured Text Ad

Featured Ad