Skip to content

Commit 5244008

Browse files
authored
Update and rename specialcharacter.js to specialcharacter.js
- Moved the script to the new created folder in Regular Expressions. - Refactored/fixed the code: -- Renamed regex variable to disallowedChars for clarity. -- Escaped special characters inside the regex to correctly match (, ), [, and ]. -- Added detailed comments explaining the purpose and structure of the regular expression. -- Replaced placeholder field name with a variable for easier reuse and readability. -- Improved error messaging to clearly inform users about invalid input.
1 parent c484783 commit 5244008

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

Client-Side Components/Client Scripts/Field Validation/specialcharacter.js

Lines changed: 0 additions & 15 deletions
This file was deleted.
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, isTemplate) {
2+
// Exit early if the form is loading, in template mode, or the new value is empty
3+
if (isLoading || newValue === '') {
4+
return;
5+
}
6+
7+
/**
8+
* Define a regular expression to match disallowed special characters.
9+
* Breakdown of the pattern:
10+
* [~@|$^<>*+=;?`'\)\(\[\]]
11+
* * - Square brackets [] define a character class, meaning "match any one of these characters".
12+
* - ~ @ | $ ^ < > * + = ; ? ` ' ) ( [ ] : These are the characters being checked.
13+
* - Characters that have special meaning inside a character class (like `(`, `)`, `[`, `]`) must be escaped with a backslash `\`.
14+
*/
15+
var disallowedChars = /[~@|$^<>*+=;?`'\)\(\[\]]/;
16+
17+
var fieldName = '<your_field_name>'; // Replace with the actual field name being validated
18+
19+
// Check if the new value contains any disallowed characters
20+
if (disallowedChars.test(newValue)) {
21+
g_form.clearValue(fieldName);
22+
g_form.showErrorBox(fieldName, 'Special characters are not allowed.');
23+
}
24+
}

0 commit comments

Comments
 (0)