Skip to content

Commit 3b8c8b2

Browse files
Create White Space Validation.js
1 parent 05b9e6a commit 3b8c8b2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function onChange(control, oldValue, newValue, isLoading) {
2+
if (isLoading || !newValue) return;
3+
4+
var fieldName = control.name;
5+
6+
// Check for any whitespace
7+
if (newValue.includes(' ')) {
8+
// Show inline error message below the field
9+
if (g_form.showFieldMsg) {
10+
g_form.showFieldMsg(
11+
fieldName,
12+
'This field cannot contain spaces.',
13+
'error',
14+
false // false = show below the field
15+
);
16+
}
17+
18+
// Clear the field
19+
g_form.setValue(fieldName, '');
20+
} else {
21+
// Remove any previous message if input is valid
22+
if (g_form.hideFieldMsg) g_form.hideFieldMsg(fieldName, true);
23+
}
24+
}

0 commit comments

Comments
 (0)