I\'m trying to validate the content of a using JavaScript, So I created a validate() function, which returns
An example with validate.js which has well tested routines for testing a valid FQDN. Alternatively look through the source and grab what you need.
function validate (e) {
var target = e.target || e;
target.value.split(',').some(function (item) {
var notValid = !validator.isFQDN(item.trim());
if (notValid) {
target.classList.add('bad');
} else {
target.classList.remove('bad');
}
return notValid;
});
}
var domains = document.getElementById('domains');
domains.addEventListener('change', validate);
validate(domains);
#domains {
width: 300px;
height: 100px;
}
.bad {
background-color: red
}