lazypanda07

script

Dec 6th, 2021
636
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.addEventListener("resize", onWindowResize);
  2.  
  3. function onWindowResize(event)
  4. {
  5.     const newWindowWidth = window.innerWidth;
  6.     const newWidthHeight = window.innerHeight;
  7.  
  8.     // TODO: Изменить стили в зависимости от новых значений высоты и ширины
  9. }
  10.  
  11. function validateEmail(email)
  12. {
  13.     const emailRegularExpression = RegExp('^(([^<>()[\\]\\.,;:\\s@\\"]+(\\.[^<>()[\\]\\.,;:\\s@\\"]+)*)|(\\".+\\"))@(([^<>()[\\]\\.,;:\\s@\\"]+\\.)+[^<>()[\\]\\.,;:\\s@\\"]{2,})$');
  14.  
  15.     return emailRegularExpression.test(email);
  16. }
  17.  
  18. function isPhoneNumber(number)
  19. {
  20.     const phoneNumberRegularExpression = RegExp('^(\\+{0,})(\\d{0,})([(]{1}\\d{1,3}[)]{0,}){0,}(\\s?\\d+|\\+\\d{2,3}\\s{1}\\d+|\\d+){1}[\\s|-]?\\d+([\\s|-]?\\d+){1,2}(\\s){0,}$');
  21.  
  22.     return phoneNumberRegularExpression.test(number);
  23. }
  24.  
  25. function validate()
  26. {
  27.     const isEmailValid = validateEmail(document.getElementById("email").value);
  28.     const isPhoneNumberValid = isPhoneNumber(document.getElementById("phone").value);
  29.  
  30.     if (!isEmailValid) {
  31.         alert("Email is not valid");
  32.     }
  33.  
  34.     if (!isPhoneNumberValid) {
  35.         alert("Phone number is not valid");
  36.     }
  37.  
  38.     return isEmailValid && isPhoneNumberValid;
  39. }
  40.  
RAW Paste Data