Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function student_information() {
- $('form[name=regform]').submit(function(){
- return student_validation();
- });
- $('tr#com_city_row').hide();
- $('select#com_country').change(function(){
- if ( this.value == 'Malaysia' ) {
- $('tr#com_city_row').show();
- } else {
- $('tr#com_city_row').hide();
- }
- });
- }
- function mail_check(mail) {
- if (mail == undefined) //mail is empty
- return "^[-'\\w]+(?:\\.[-'\\w]+)*@[-\\w]+(?:\\.[-\\w]+)+$";
- else
- return /^[-'\w]+(?:\.[-'\w]+)*@[-\w]+(?:\.[-\w]+)+$/.test(mail); //
- }
- function check_form(form_element, regex_string, error_message) {
- var re = new RegExp(regex_string);
- if (!form_element.value.match(re)) {
- if (error_message != undefined) {
- alert(error_message); //if error is sent, alert. else, return value only
- form_element.focus();
- }
- return false;
- }
- return true;
- }
- function student_validation() {
- // Check Student ID
- if (!check_form(document.regform.stu_id, '.+', 'Student ID cannot be empty'))
- return false;
- if (!check_form(document.regform.stu_id, '^\\d{10}$', 'Student ID must be 10-digit numbers'))
- return false;
- // Check Student Name
- if (!check_form(document.regform.stu_name, '.+', 'Student name cannot be empty'))
- return false;
- // Check Email
- if (!check_form(document.regform.stu_email, mail_check(), 'This is not a valid email address'))
- return false;
- // Check Company Name
- if (!check_form(document.regform.com_name, '.+', 'Company Name cannot be empty'))
- return false;
- // Check Company Country
- if (!check_form(document.regform.com_country, '.+', 'Country cannot be empty'))
- return false;
- if (check_form(document.regform.com_country, '^Malaysia$'))
- if (!check_form(document.regform.com_city, '.+', 'City cannot be empty'))
- return false;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement