Advertisement
bebo231312312321

Untitled

Jun 2nd, 2023
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function validate() {
  2.     document.getElementById('company').addEventListener('change', (e) => {
  3.         let companyInfo = document.getElementById('companyInfo');
  4.         document.getElementById('company').cheked == false ? companyInfo.style.display = 'none' : companyInfo.style.display = 'block'
  5.     });
  6.     document.getElementById('submit').addEventListener('click', onClick);
  7.  
  8.     function onClick(event) {
  9.         event.preventDefault();
  10.         const inValid = [];
  11.         const checkBox = document.querySelector('#company');
  12.         const userName = document.getElementById('username');
  13.  
  14.         if (!/^[A-Za-z0-9]{3,20}$/.test(userName.value)) inValid.push(userName);
  15.         // /^[^@.]+@[^@]*\.[^@]+$/;
  16.         const mailField = document.getElementById('email');
  17.  
  18.         if (!/^[^@.]+@[^@]*\.[^@]*$/.test(mailField.value)) inValid.push(mailField);
  19.         const pass = document.getElementById('password');
  20.         const confirmPass = document.getElementById('confirm-password');
  21.  
  22.         if (!/^[\w]{5,15}$/.test(pass.value) || confirmPass.value !== pass.value || confirmPass.value === '')
  23.             (inValid.push(pass)), (inValid.push(confirmPass));
  24.  
  25.         if (checkBox.checked) {
  26.             const copmanyId = document.getElementById('companyNumber');
  27.             if (!/^[0-9]{4}$/.test(copmanyId.value)) inValid.push(copmanyId);
  28.         };
  29.  
  30.         inValid.forEach(field => field.style.borderColor = 'red');
  31.         !inValid.length ? document.querySelector('#valid').style.display = 'block' : document.querySelector('#valid').style.display = 'none';
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement