Advertisement
fbinnzhivko

Untitled

May 10th, 2017
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(){
  2.  
  3.     let isCompany = false;
  4.     setEventHandlers();
  5.  
  6.  
  7.     function setEventHandlers() {
  8.         $("#registerForm").submit(function(e) {
  9.             e.preventDefault();
  10.             ValidateData();
  11.         });
  12.  
  13.         $("#company").on("change", function () {
  14.             if ($("#company").is(":checked")){
  15.                 $("#companyInfo").show();
  16.                 isCompany = true;
  17.             }
  18.             else{
  19.                 $("#companyInfo").hide();
  20.                 isCompany = false;
  21.             }
  22.         });
  23.     }
  24.  
  25.     function ValidateData() {
  26.         let formIsValid = true;
  27.  
  28.         let username = $('#username').val();
  29.         if (!username.match(/^[a-zA-Z0-9]{3,20}$/)){
  30.             $('#username').css('border-color', 'red');
  31.             formIsValid = false;
  32.         }
  33.         else{
  34.             $('#username').css('border', 'none');
  35.         }
  36.  
  37.         let email = $('#email').val();
  38.         if (!email.match(/^.*@.*\..*$/)){
  39.             $('#email').css('border-color', 'red');
  40.             formIsValid = false;
  41.         }
  42.         else{
  43.             $('#email').css('border', 'none');
  44.         }
  45.  
  46.         let password = $('#password').val();
  47.         let confirmPassword = $('#confirm-password').val();
  48.  
  49.         console.log(password);
  50.         console.log(confirmPassword);
  51.  
  52.         if (!password.match(/^[\w]{5,15}$/)){
  53.             $('#password').css('border-color', 'red');
  54.             $('#confirm-password').css('border-color', 'red');
  55.             formIsValid = false;
  56.         }
  57.         else{
  58.             if (!confirmPassword.match(/^[\w]{5,15}$/) ||
  59.                 password != confirmPassword){
  60.                 $('#password').css('border-color', 'red');
  61.                 $('#confirm-password').css('border-color', 'red');
  62.                 formIsValid = false;
  63.             }
  64.             else{
  65.  
  66.                 $('#password').css('border', 'none');
  67.                 $('#confirm-password').css('border', 'none');
  68.             }
  69.         }
  70.  
  71.         if (isCompany){
  72.             let companyNumber = $("#companyNumber").val();
  73.             if (!companyNumber.match(/^[1-9][0-9]{3}$/)){
  74.                 $("#companyNumber").css('border-color', 'red');
  75.                 formIsValid = false;
  76.             }
  77.             else{
  78.                 $("#companyNumber").css('border', 'none');
  79.             }
  80.         }
  81.  
  82.         console.log(formIsValid);
  83.         if (formIsValid){
  84.             $('#valid').show();
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement