Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tm_validator.js 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. function validate(container_id) {
  2. var final_flag = [];
  3. var final_answer;
  4. $(container_id + ' .input-group').each(function(k3, v3) {
  5. if($(this).children('input').length != 0)
  6. {
  7. method = 'text';
  8. }
  9. else if($(this).children('select').length != 0)
  10. {
  11. method = 'select';
  12. }
  13. else if($(this).children('textarea').length != 0)
  14. {
  15. method = 'textarea';
  16. }
  17. else{
  18. method = null;
  19. valid_type = 'nullable';
  20. }
  21. if(method == 'text')
  22. {
  23. input_val = $(this).children('input').val();
  24. valid_type = $(this).find('input').data('validate');
  25. }
  26. else if(method == 'select')
  27. {
  28. input_val = $(this).children('select').val();
  29. valid_type1 = $(this).children('select').data('validate');
  30. valid_type = valid_type1 == 'nullable' ? 'nullable' : 'select_spcl';
  31. idropdown = $(this).children('select').attr('idropdown');
  32. }
  33. //console.log(container_id);
  34. var current_flag = false;
  35. if (valid_type == 'text') {
  36. current_flag = input_val.length > 1 ? true : false
  37. } else if (valid_type == 'number') {
  38. var no = /^\d+$/;
  39. current_flag = no.test(input_val);
  40. } else if (valid_type == 'nospace') {
  41. var no = /^[a-zA-Z0-9-_@.]+$/;
  42. current_flag = no.test(input_val);
  43. } else if (valid_type == 'nullable') {
  44. current_flag = true;
  45. } else if (valid_type == 'email') {
  46. var rx = /^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]+?\.[A-Za-z0-9_\-\.]{2,8}$/;
  47. current_flag = rx.test(input_val);
  48. } else if (valid_type == 'password') {
  49. current_flag = input_val.length > 0 ? true : false;
  50. } else if (valid_type == 'contact') {
  51. inp = parseInt(input_val, 10);
  52. current_flag = inp < 9999999999 && inp > 1000000000 ? true : false;
  53. } else if (valid_type == 'select_spcl') {
  54. current_flag = input_val == 0 || input_val == '' ? false : true;
  55. }
  56. if (!current_flag) {
  57. $(this).removeClass('success').addClass('error');
  58. if (valid_type == 'select_spcl')
  59. {
  60. $(this).children('.icontainer').removeClass('select2_theme').addClass('select2_red');
  61. $('.'+idropdown).removeClass('select2_theme').addClass('select2_red');
  62. }
  63. } else {
  64. $(this).removeClass('error').addClass('success');
  65. if (valid_type == 'select_spcl')
  66. {
  67. $(this).children('.icontainer').removeClass('select2_theme select2_red').addClass('select2_green');
  68. $('.'+idropdown).removeClass('select2_theme select2_red').addClass('select2_green');
  69. }
  70. }
  71. final_flag.push(current_flag);
  72. if (k3 == $(container_id + ' .input-group').length - 1) {
  73. final_answer = true;
  74. $.each(final_flag, function(k2, v2) {
  75. if (!v2) {
  76. final_answer = false;
  77. }
  78. });
  79. yff = $('.pt-wrapper').outerHeight();
  80. y_h = $(container_id).outerHeight();
  81. if(yff < y_h)
  82. {
  83. $('.pt-wrapper').css('height',y_h);
  84. }
  85. }
  86. });
  87. return final_answer;
  88. }