Advertisement
kstoyanov

07. Dynamic Validation

Oct 1st, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function validate() {
  2.     const emailInput = document.getElementById('email');
  3.     emailInput.addEventListener('change', function (e) {
  4.         emailInput.classList.remove('error');
  5.         const value = emailInput.value;
  6.         if (value.match(/^[a-z-\.]+@[a-z-\.]+\.[a-z]{2,4}/)) {
  7.             return;
  8.         }
  9.         emailInput.classList.add('error');
  10.     });
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement