

   function text (str) { return /[0-9_;:!~?=+<|>]/g.test(str); }

   function numeric (str) { return /^[0-9-\+\(\)\s]+z/.test(str + "z"); }

   function mail (str) { return /^[a-z0-9_\-.]+@[a-z0-9_\.]+.[a-z]{2,3}$/.test(str); }

   function checkForm ()
      {
      var title;
      var elem;
      var dutyField = "Не заполнено поле ";
      var wrongField = "Неверное значение поля ";
      var check = true;

      function checkError (field, str)
         {
         document.getElementById("alert").innerHTML = str;
         document.forms.ship.field.focus();
         check = false;
         }

      document.getElementById("alert").innerHTML = "";

   
      if (check)
         {
         title = '"ФИО"';
         elem = document.ship.name.value;
         if (elem.length == 0) checkError('name', dutyField + title);
         else if (text(elem)) checkError('name', wrongField + title);
         }
         
      if (check)
         {
         title = '"Email"';
         elem = document.ship.email.value;
         if (elem.length == 0) checkError('email', dutyField + title);
         else if (!mail(elem)) checkError('email', wrongField + title);
         }

      if (check)
         {
         title = '"Телефон"';
         elem = document.ship.phone.value;
         if (elem.length == 0) checkError('phone', dutyField + title);
         else if (!numeric(elem)) checkError('phone', wrongField + title);
         }
         
          
         
      if (check)  { document.ship.submit(); }

      return check;
      }

