<input type='text' id = 'username'>
<input type='text' id = 'pas'>
<button>Тест</button>
<script>
document.querySelector('button').onclick = validate;
function validate() {
const expressions = {
email: /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/,
password: /(?=.*[0-9])(?=.*[!@#$%^&*])(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z!@#$%^&*]{6,}/g
};
return !['username', 'pas'].filter((id, i) => {
const node = document.getElementById(id);
const isValid = (node.value.length && expressions[!i ? 'email' : 'password'].test(node.value));
node.style.borderColor = isValid ? 'green' : 'red';
return !isValid;
}).length;
}
</script>