Email id validation script

Discussion in 'JavaScript' started by subha rr, Apr 18, 2009.

  1. #1
    Hi.....

    how do I check if a value is in an array

    var arr = new Array('.com','.net','.org','.biz','.coop','.info','.museum','.name','.pro'
    ,'.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag','.ai','.al'...........);

    Regards
    Subha
     
    subha rr, Apr 18, 2009 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    flatten the array and use indexOf ...

    var foo = ['.com','.net','.org','.biz','.coop','.info','.museum','.name','.pro' ,'.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag','.ai','.al'], fooFlat = foo.join(","), isAllowed = function(what) {
        return (foo.indexOf(what) != -1) ? true : false;
    };  
    
    // example use...
    if (isAllowed(".com")) {
        alert("found .com");
    }
    
    if (isAllowed(".it")) {
        alert("found .it");
    }
    else {
        alert("not found .it!");
    }
    
    alert(((isAllowed(".org")) ? "found" : "not found") + " .org");
    
    PHP:
     
    dimitar christoff, Apr 18, 2009 IP