Get company from email domain
by Tymoteusz Czech
HTML
<input type="text" id="input">
<br>
<span id="output"></span>
<span id="debug"></span>
JavaScript
(function () {
function test(input) {
var expr = new RegExp("(.)([^\\.]+)?.*", 'i');
expr = expr.exec(input);
if (expr === null) {
return "";
}
return expr[1].toUpperCase() + ((expr[2] !== undefined) ? expr[2] : "");
};
function test2(input) {
var i, j,
companies = [],
company,
domains = [],
domain,
expr = new RegExp(".+@(.*)", 'i'),
data = {
"Google Inc.": ["gmail.com"],
"Grupa Onet.pl SA": ["onet.pl", "op.pl", "vp.pl", "spoko.pl", "vip.onet.pl", "autograf.pl", "onet.com.pl", "opoczta.pl", "onet.eu", "poczta.onet.eu"],
"Microsoft Corporation": ["outlook.com", "hotmail.com", "live.com"],
"Yahoo! Inc.": ["yahoo.com"],
"Grupa Wirtualna Polska Sp. z o.o. ": ["wp.pl", "o2.pl", "tlen.pl", "go2.pl", "prokonto.pl"]
};
expr = expr.exec(input);
if (expr === null) {
return "";
} else {
input = expr[1];
console.log(input);
}
for (company in data) {
if (data.hasOwnProperty(company)) {
companies.push(company);
domains.push(data[company]);
}
}
for (i = 0; i < companies.length; i += 1) {
for (j = 0; j < domains[i].length; j += 1) {
if (domains[i][j] === input) {
return companies[i];
}
}
}
return test(input);
};
$("#input").on('keyup', function (e) {
var x = $(this).val();
$("#output").text(test2(x));
});
}());