diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index ee3a8098..7b570ae8 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1013,9 +1013,8 @@ class ClientController extends AdminController ] ], 'pan' => [ - 'rules' => 'required|regex_match[/^[A-Z]{5}[0-9]{4}[A-Z]$/]', + 'rules' => 'permit_empty|regex_match[/^[A-Z]{5}[0-9]{4}[A-Z]$/]', 'errors' => [ - 'required' => 'PAN Number is required.', 'regex_match' => 'Invalid PAN format. Example: ABCDE1234F' ] ], @@ -1129,9 +1128,8 @@ class ClientController extends AdminController ] ], 'pan' => [ - 'rules' => 'required|regex_match[/^[A-Z]{5}[0-9]{4}[A-Z]$/]', + 'rules' => 'permit_empty|regex_match[/^[A-Z]{5}[0-9]{4}[A-Z]$/]', 'errors' => [ - 'required' => 'PAN Number is required.', 'regex_match' => 'Invalid PAN format. Example: ABCDE1234F' ] ], @@ -5803,6 +5801,99 @@ class ClientController extends AdminController // print_r($postData); die; $client_type = $postData['client_type'] ?? null; + $from_modal = $postData['from_modal'] ?? null; + + $rules = [ + 'client_name' => [ + 'label' => 'Client Name', + 'rules' => 'required|regex_match[/^[a-zA-Z0-9 ,\/_\-]+$/]', + 'errors' => [ + 'required' => 'Client Name is required.', + 'regex_match' => 'Client Name only allows letters, numbers, spaces, and , / _ -' + ] + ], + 'short_name' => [ + 'label' => 'Client Short Name', + 'rules' => 'required|regex_match[/^[a-zA-Z0-9,\/_\-]+$/]|is_unique[clients.short_name]', + 'errors' => [ + 'required' => 'Short Name is required.', + 'regex_match' => 'Short Name only allows letters, numbers, and , / _ -', + 'is_unique' => 'This Short Name is already in use.' + ] + ], + 'pan' => [ + 'label' => 'PAN', + 'rules' => 'permit_empty|regex_match[/^[A-Z]{5}[0-9]{4}[A-Z]{1}$/]', + 'errors' => [ + 'regex_match' => 'Invalid PAN format (Example: ABCDE1234F).' + ] + ], + 'entity_type_id' => [ + 'label' => 'Entity Type', + 'rules' => 'required', + 'errors' => [ + 'required' => 'Please select an Entity Type.' + ] + ], + 'branch_name' => [ + 'label' => 'Branch Name', + 'rules' => 'required|regex_match[/^[a-zA-Z0-9 ,\/_\-]+$/]', + 'errors' => [ + 'required' => 'Branch Name is required.', + 'regex_match' => 'Branch Name only allows letters, numbers, spaces, and , / _ -' + ] + ], + 'branch_code' => [ + 'label' => 'Branch Code', + 'rules' => 'required|regex_match[/^[a-zA-Z0-9,\/_\-]+$/]', + 'errors' => [ + 'required' => 'Branch Code is required.', + 'regex_match' => 'Branch Code only allows letters, numbers, and , / _ -' + ] + ], + 'name' => [ + 'label' => 'Contact Person Name', + 'rules' => 'required|regex_match[/^[a-zA-Z0-9 ,\/_\-]+$/]', + 'errors' => [ + 'required' => 'Name is required.', + 'regex_match' => 'Name only allows letters, numbers, spaces, and , / _ -' + ] + ], + 'mobile' => [ + 'label' => 'Mobile', + 'rules' => 'required|numeric|exact_length[10]', + 'errors' => [ + 'required' => 'Mobile number is required.', + 'numeric' => 'Mobile must contain only digits.', + 'exact_length' => 'Mobile number must be exactly 10 digits.' + ] + ], + 'email' => [ + 'label' => 'Email', + 'rules' => 'required|valid_email', + 'errors' => [ + 'required' => 'Email is required.', + 'valid_email' => 'Please provide a valid email address.' + ] + ], + 'gst' => [ + 'label' => 'GST', + 'rules' => 'required|regex_match[/^\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}[Z]{1}[A-Z\d]{1}$/]', + 'errors' => [ + 'required' => 'GST Number is required.', + 'regex_match' => 'Invalid GST format (Example: 12ABCDE1234F5Z6).' + ] + ] + ]; + + if (isset($from_modal) && !$this->validate($rules)) { + return $this->response->setStatusCode(400)->setJSON([ + 'status' => false, + 'message' => 'Input validation failed', + 'code' => 400, + 'errors' => $this->validator->getErrors() + ]); + } $client_insert = null; if ($client_type == 2) { @@ -5928,7 +6019,8 @@ class ClientController extends AdminController ], ]; - if (!$this->validate($rules)) { + + if (!$this->validate($rules)) { return $this->response->setStatusCode(400)->setJSON([ 'status' => false, 'message' => 'Input validation failed', @@ -5936,6 +6028,7 @@ class ClientController extends AdminController 'errors' => $this->validator->getErrors() ]); } + $data = $this->request->getPost(); $sanitized_post_data = sanitizeInputArrayAdvanced($data); $id = $sanitized_post_data['vehicle_primary_key'] ?? null; diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index dfbac180..2d99b088 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -1290,7 +1290,13 @@ class TicketController extends BaseController ] ], // --- ADDITIONAL / CONDITIONAL FIELDS --- - 'claim_number' => ['label' => 'Claim Number','rules' => 'permit_empty|alpha_numeric_punct','errors' => ['alpha_numeric_punct' => 'Invalid Claim Number.']], + 'claim_number' => [ + 'label' => 'Claim Number', + 'rules' => 'permit_empty|regex_match[/^[a-zA-Z0-9\/_-]+$/]', + 'errors' => [ + 'regex_match' => 'Claim Number only allows letters, numbers, slashes (/), hyphens (-), and underscores (_).' + ] + ], 'denial_date' => ['label' => 'Denial Date','rules' => 'permit_empty|regex_match[/^\d{2}\/\d{2}\/\d{4}$/]','errors' => ['regex_match' => 'Denial Date must be dd/mm/yyyy.']], 'approved_amount' => ['label' => 'Approved Amount','rules' => 'permit_empty|numeric', 'errors' => ['numeric' => 'Approved amount must be numeric'] @@ -1649,7 +1655,13 @@ class TicketController extends BaseController ], // --- ADDITIONAL / CONDITIONAL FIELDS --- - 'claim_number' => ['label' => 'Claim Number','rules' => 'permit_empty|alpha_numeric_punct','errors' => ['alpha_numeric_punct' => 'Invalid Claim Number.']], + 'claim_number' => [ + 'label' => 'Claim Number', + 'rules' => 'permit_empty|regex_match[/^[a-zA-Z0-9\/_-]+$/]', + 'errors' => [ + 'regex_match' => 'Claim Number only allows letters, numbers, slashes (/), hyphens (-), and underscores (_).' + ] + ], 'denial_date' => ['label' => 'Denial Date','rules' => 'permit_empty|regex_match[/^\d{2}\/\d{2}\/\d{4}$/]','errors' => ['regex_match' => 'Denial Date must be dd/mm/yyyy.']], 'approved_amount' => ['label' => 'Approved Amount','rules' => 'permit_empty|numeric', 'errors' => ['numeric' => 'Approved amount must be numeric'] diff --git a/app/Views/cd_master_add_modal.php b/app/Views/cd_master_add_modal.php index c8bf0f05..28579d01 100644 --- a/app/Views/cd_master_add_modal.php +++ b/app/Views/cd_master_add_modal.php @@ -67,8 +67,7 @@
- - +
@@ -366,4 +365,33 @@ } } + $(document).ready(function() { + // Target the input by its ID + $('#cd_ac_no_for_cd_master').on('keypress', function(e) { + // Get the character code + var keyCode = e.which || e.keyCode; + var char = String.fromCharCode(keyCode); + + // Regular Expression: allow a-z, A-Z, 0-9, /, -, _ + // If the character doesn't match, prevent it from being typed + var regex = /^[a-zA-Z0-9\/_-]+$/; + + if (!regex.test(char)) { + e.preventDefault(); + // Optional: Show a quick error message in your span + $('#cd_ac_no_for_cd_master_errorr').text('Character not allowed').fadeOut(2000, function() { + $(this).text('').show(); + }); + return false; + } + }); + + // Also handle "Paste" to ensure invalid data isn't pasted in + $('#cd_ac_no_for_cd_master').on('input', function() { + var value = $(this).val(); + var sanitized = value.replace(/[^a-zA-Z0-9\/_-]/g, ''); + $(this).val(sanitized); + }); + }); + \ No newline at end of file diff --git a/app/Views/client_basic_info.php b/app/Views/client_basic_info.php index a8de6ec7..2227c841 100755 --- a/app/Views/client_basic_info.php +++ b/app/Views/client_basic_info.php @@ -124,8 +124,8 @@ input:checked + .slider:before {
- - + +