svetlio_top

Dynamic Validation

Dec 31st, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function validate() {
  2.     var reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  3.     const inputField = document.getElementById('email');
  4.     inputField.addEventListener('input', function(){
  5.         if(reg.test(inputField.value)){
  6.             inputField.classList.remove('error');
  7.                    
  8.                 }else{
  9.                     inputField.classList.add('error');
  10.                 }
  11.     });
  12. }
Add Comment
Please, Sign In to add comment