Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function student_information() {
  2.   $('form[name=regform]').submit(function(){
  3.     return student_validation();
  4.   });
  5.  
  6.   $('tr#com_city_row').hide();
  7.  
  8.   $('select#com_country').change(function(){
  9.     if ( this.value == 'Malaysia' ) {
  10.       $('tr#com_city_row').show();
  11.     } else {
  12.       $('tr#com_city_row').hide();
  13.     }
  14.   });
  15. }
  16.  
  17.  
  18.  
  19. function mail_check(mail) {
  20.   if (mail == undefined) //mail is empty
  21.     return "^[-'\\w]+(?:\\.[-'\\w]+)*@[-\\w]+(?:\\.[-\\w]+)+$";
  22.   else
  23.     return /^[-'\w]+(?:\.[-'\w]+)*@[-\w]+(?:\.[-\w]+)+$/.test(mail); //
  24. }
  25.  
  26.  
  27. function check_form(form_element, regex_string, error_message) {
  28.   var re = new RegExp(regex_string);
  29.   if (!form_element.value.match(re)) {
  30.     if (error_message != undefined) {
  31.       alert(error_message); //if error is sent, alert. else, return value only
  32.       form_element.focus();
  33.     }
  34.     return false;
  35.   }
  36.   return true;
  37. }
  38.  
  39. function student_validation() {
  40.  
  41.   // Check Student ID
  42.   if (!check_form(document.regform.stu_id, '.+', 'Student ID cannot be empty'))
  43.     return false;
  44.  
  45.   if (!check_form(document.regform.stu_id, '^\\d{10}$', 'Student ID must be 10-digit numbers'))
  46.     return false;
  47.  
  48.   // Check Student Name
  49.   if (!check_form(document.regform.stu_name, '.+', 'Student name cannot be empty'))
  50.     return false;
  51.  
  52.  // Check Email
  53.   if (!check_form(document.regform.stu_email, mail_check(), 'This is not a valid email address'))
  54.     return false;
  55.  
  56.  // Check Company Name
  57.   if (!check_form(document.regform.com_name, '.+', 'Company Name cannot be empty'))
  58.     return false;
  59.  
  60.   // Check Company Country
  61.   if (!check_form(document.regform.com_country, '.+', 'Country cannot be empty'))
  62.     return false;
  63.  
  64.   if (check_form(document.regform.com_country, '^Malaysia$'))
  65.     if (!check_form(document.regform.com_city, '.+', 'City cannot be empty'))
  66.       return false;
  67.  
  68.   return true;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement