Skip to content

Commit 2bc7bee

Browse files
authored
Update PAN Validation.js
Improves PAN validation by showing errors only for invalid input, reducing distractions and unnecessary messages. Also used newValue to take input as it is a onChange Script
1 parent 540163a commit 2bc7bee

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
22
if (isLoading || newValue === '') {
3+
// Clear any previous message if the field is empty
4+
g_form.hideFieldMsg('pan_number');
35
return;
46
}
5-
var panNumber = g_form.getValue("pan_number"); //Get the PAN card information
6-
var panRegex = /^[A-Z]{5}[0-9]{4}[A-Z]{1}$/; // Regex for the PAN Card
77

8-
if (panRegex.test(panNumber)) {
9-
g_form.showFieldMsg("pan_number", "Valid PAN card number.", true); //Valid PAN card enterd populates this message
10-
} else {
11-
g_form.showErrorBox("pan_number", "InValid PAN card number.", true); //In Valid PAN card details enterd populate this message
8+
var panNumber = newValue.toUpperCase(); // Convert input to uppercase for consistency
9+
var panRegex = /^[A-Z]{5}[0-9]{4}[A-Z]{1}$/;
10+
11+
if (!panRegex.test(panNumber)) {
12+
g_form.showFieldMsg('pan_number', 'Invalid PAN card number.', 'error');
1213
}
14+
// No "Valid" message displayed to reduce distraction
1315
}

0 commit comments

Comments
 (0)