Skip to content

Commit 0219153

Browse files
Create Number Validation Script.js
1 parent 7490d8d commit 0219153

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function onChange(control, oldValue, newValue, isLoading, g_form) {
2+
if (isLoading || newValue === '') return;
3+
4+
var fieldName = control.name;
5+
var fieldLabel = g_form.getLabel ? g_form.getLabel(fieldName) : fieldName;
6+
var numericPattern = /^[0-9]+$/;
7+
8+
// Hide old messages safely
9+
if (g_form.hideFieldMsg) g_form.hideFieldMsg(fieldName, true);
10+
11+
// Validation logic
12+
if (!numericPattern.test(newValue)) {
13+
// Reset only if API supported
14+
if (g_form.setValue && typeof g_form.setValue === 'function') {
15+
g_form.setValue(fieldName, oldValue);
16+
}
17+
18+
// Show the message directly below the field
19+
if (g_form.showFieldMsg) {
20+
g_form.showFieldMsg(
21+
fieldName,
22+
'Please enter numbers only', // your custom message
23+
'error',
24+
false // false = display under the field, not at top
25+
);
26+
} else {
27+
alert('Short Description filed accepts numbers only');
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)