<input type='text' id = 'username'>
<button>Тест</button>
<script>
var userEmail = document.getElementById("username");
var regexp = new RegExp("^([a-z0-9_-]+\.)*[a-z0-9_-]+@[a-z0-9_-]+(\.[a-z0-9_-]+)*\.[a-z]{2,6}$");
document.querySelector('button').onclick = function() {
if(!regexp.test(userEmail.value)) {
userEmail.style.border = "2px solid red";
} else {
userEmail.style.border = "2px solid green";
}
}
</script>