Virajsinh

FormValidation With Remote Check Email And Phone is Exist Or Not Jquery

Oct 1st, 2025 (edited)
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 4.22 KB | Source Code | 0 0
  1. <script type="text/javascript">
  2.     const form = document.querySelector('#employee_create_form');
  3.     var addValidator = FormValidation.formValidation(
  4.         form, {
  5.             fields: {
  6.                 'company_id': {
  7.                     validators: {
  8.                         notEmpty: {
  9.                             message: 'Select Company'
  10.                         }
  11.                     }
  12.                 },
  13.                 'first_name': {
  14.                     validators: {
  15.                         notEmpty: {
  16.                             message: 'First Name is required'
  17.                         }
  18.                     }
  19.                 },
  20.                 'middle_name': {
  21.                     validators: {
  22.                         notEmpty: {
  23.                             message: 'Middle Name is required'
  24.                         }
  25.                     }
  26.                 },
  27.                 'last_name': {
  28.                     validators: {
  29.                         notEmpty: {
  30.                             message: 'Last Name is required'
  31.                         }
  32.                     }
  33.                 },
  34.                 'date_of_birth': {
  35.                     validators: {
  36.                         notEmpty: {
  37.                             message: 'Date Of Birth is required'
  38.                         }
  39.                     }
  40.                 },
  41.                 'gender': {
  42.                     validators: {
  43.                         notEmpty: {
  44.                             message: 'Gender is required'
  45.                         }
  46.                     }
  47.                 },
  48.                 'marital_status': {
  49.                     validators: {
  50.                         notEmpty: {
  51.                             message: 'Marital Status is required'
  52.                         }
  53.                     }
  54.                 },
  55.                 'email': {
  56.                     validators: {
  57.                         notEmpty: {
  58.                             message: 'Email is required'
  59.                         },
  60.                         emailAddress: {
  61.                             message: 'The input is not a valid email address'
  62.                         },
  63.                         remote: {
  64.                             message: 'Email is already registered',
  65.                             method: 'GET',
  66.                             url: backend_url+'/users/check-email',  // change this
  67.                             data: function() {
  68.                                 return {
  69.                                     email: form.querySelector('[name="email"]').value
  70.                                 };
  71.                             },
  72.                             delay: 0, // wait 500ms after last input before sending ajax
  73.                         }
  74.                     }
  75.                 },
  76.                 'phone': {
  77.                     validators: {
  78.                         notEmpty: {
  79.                             message: 'Phone is required'
  80.                         },
  81.                         remote: {
  82.                             message: 'Phone is already registered',
  83.                             method: 'GET',
  84.                             url: backend_url+'/users/check-phone',  // change this
  85.                             data: function() {
  86.                                 return {
  87.                                     email: form.querySelector('[name="phone"]').value
  88.                                 };
  89.                             },
  90.                             delay: 0, // wait 500ms after last input before sending ajax
  91.                         }
  92.                     }
  93.                 },
  94.                 'date_of_join': {
  95.                     validators: {
  96.                         notEmpty: {
  97.                             message: 'Date Of Join is required'
  98.                         }
  99.                     }
  100.                 },
  101.                 'employee_type_id': {
  102.                     validators: {
  103.                         notEmpty: {
  104.                             message: 'Employee Type is required'
  105.                         }
  106.                     }
  107.                 },
  108.                 'department_id': {
  109.                     validators: {
  110.                         notEmpty: {
  111.                             message: 'Department is required'
  112.                         }
  113.                     }
  114.                 },
  115.                 'designation_id': {
  116.                     validators: {
  117.                         notEmpty: {
  118.                             message: 'Designation is required'
  119.                         }
  120.                     }
  121.                 },
  122.                 'permanent_state_id': {
  123.                     validators: {
  124.                         notEmpty: {
  125.                             message: 'Permanent State is required'
  126.                         }
  127.                     }
  128.                 },
  129.                 'permanent_city': {
  130.                     validators: {
  131.                         notEmpty: {
  132.                             message: 'Permanent City is required'
  133.                         }
  134.                     }
  135.                 },
  136.                 'permanent_address': {
  137.                     validators: {
  138.                         notEmpty: {
  139.                             message: 'Permanent Address is required'
  140.                         }
  141.                     }
  142.                 },
  143.                 'current_state_id': {
  144.                     validators: {
  145.                         notEmpty: {
  146.                             message: 'Current State is required'
  147.                         }
  148.                     }
  149.                 },
  150.                 'current_city': {
  151.                     validators: {
  152.                         notEmpty: {
  153.                             message: 'Current City is required'
  154.                         }
  155.                     }
  156.                 },
  157.                 'current_address': {
  158.                     validators: {
  159.                         notEmpty: {
  160.                             message: 'Current Address is required'
  161.                         }
  162.                     }
  163.                 },
  164.                 /*'previous_company': {
  165.                     validators: {
  166.                         notEmpty: {
  167.                             message: 'Previous Company is required'
  168.                         }
  169.                     }
  170.                 },*/
  171.                 /*'total_experience': {
  172.                     validators: {
  173.                         notEmpty: {
  174.                             message: 'Total Experience is required'
  175.                         }
  176.                     }
  177.                 },*/
  178.                 /*'uan_number': {
  179.                     validators: {
  180.                         notEmpty: {
  181.                             message: 'UAN Number is required'
  182.                         }
  183.                     }
  184.                 },*/
  185.                 'status': {
  186.                     validators: {
  187.                         notEmpty: {
  188.                             message: 'Select Status is required'
  189.                         }
  190.                     }
  191.                 },
  192.             },
  193.  
  194.             plugins: {
  195.                 trigger: new FormValidation.plugins.Trigger({
  196.                     event: {
  197.                         email: "blur",
  198.                         phone: "blur",
  199.                     },
  200.                 }),
  201.                 bootstrap: new FormValidation.plugins.Bootstrap5({
  202.                     rowSelector: '.fv-row',
  203.                     eleInvalidClass: '',
  204.                     eleValidClass: ''
  205.                 })
  206.             }
  207.         }
  208.     );
  209. </script>
Advertisement
Add Comment
Please, Sign In to add comment