From c484783ba055dff93416decf6f2cee6820269a52 Mon Sep 17 00:00:00 2001 From: Willem Date: Fri, 10 Oct 2025 16:09:05 +0200 Subject: [PATCH 1/4] Create folder and readme.md - Created sub-folder "Check for special characters" in the Regular Expressions folder. - Added readme --- .../Regular Expressions/Check for special characters/readme.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 Specialized Areas/Regular Expressions/Check for special characters/readme.md diff --git a/Specialized Areas/Regular Expressions/Check for special characters/readme.md b/Specialized Areas/Regular Expressions/Check for special characters/readme.md new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/Specialized Areas/Regular Expressions/Check for special characters/readme.md @@ -0,0 +1 @@ + From 52440087ed98059d2df89e3116544e2601b50d32 Mon Sep 17 00:00:00 2001 From: Willem Date: Fri, 10 Oct 2025 16:18:14 +0200 Subject: [PATCH 2/4] 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. --- .../Field Validation/specialcharacter.js | 15 ------------ .../specialcharacter.js | 24 +++++++++++++++++++ 2 files changed, 24 insertions(+), 15 deletions(-) delete mode 100644 Client-Side Components/Client Scripts/Field Validation/specialcharacter.js create mode 100644 Specialized Areas/Regular Expressions/Check for special characters/specialcharacter.js diff --git a/Client-Side Components/Client Scripts/Field Validation/specialcharacter.js b/Client-Side Components/Client Scripts/Field Validation/specialcharacter.js deleted file mode 100644 index 8488adbee2..0000000000 --- a/Client-Side Components/Client Scripts/Field Validation/specialcharacter.js +++ /dev/null @@ -1,15 +0,0 @@ -function onChange(control, oldValue, newValue, isLoading, isTemplate) { - - if (isLoading || newValue === '') { - return; - } - - //In the below regex, you can add or remove any special characters as per your requirement - var special_chars = /[~@|$^<>\*+=;?`')[\]]/; - - if (special_chars.test(newValue)) { - g_form.clearValue(''); - g_form.showErrorBox('','Special Characters are not allowed'); - } - -} diff --git a/Specialized Areas/Regular Expressions/Check for special characters/specialcharacter.js b/Specialized Areas/Regular Expressions/Check for special characters/specialcharacter.js new file mode 100644 index 0000000000..578247e66c --- /dev/null +++ b/Specialized Areas/Regular Expressions/Check for special characters/specialcharacter.js @@ -0,0 +1,24 @@ +function onChange(control, oldValue, newValue, isLoading, isTemplate) { + // Exit early if the form is loading, in template mode, or the new value is empty + if (isLoading || newValue === '') { + return; + } + + /** + * Define a regular expression to match disallowed special characters. + * Breakdown of the pattern: + * [~@|$^<>*+=;?`'\)\(\[\]] + * * - Square brackets [] define a character class, meaning "match any one of these characters". + * - ~ @ | $ ^ < > * + = ; ? ` ' ) ( [ ] : These are the characters being checked. + * - Characters that have special meaning inside a character class (like `(`, `)`, `[`, `]`) must be escaped with a backslash `\`. + */ + var disallowedChars = /[~@|$^<>*+=;?`'\)\(\[\]]/; + + var fieldName = ''; // Replace with the actual field name being validated + + // Check if the new value contains any disallowed characters + if (disallowedChars.test(newValue)) { + g_form.clearValue(fieldName); + g_form.showErrorBox(fieldName, 'Special characters are not allowed.'); + } +} From 4a31184bf08d655b166895aac5ddd0f0f609f56c Mon Sep 17 00:00:00 2001 From: Willem Date: Fri, 10 Oct 2025 16:19:10 +0200 Subject: [PATCH 3/4] Delete Client-Side Components/Client Scripts/Field Validation directory Deleted the old folder. Files in the folder have moved to the Regex folder. --- .../Client Scripts/Field Validation/README.md | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 Client-Side Components/Client Scripts/Field Validation/README.md diff --git a/Client-Side Components/Client Scripts/Field Validation/README.md b/Client-Side Components/Client Scripts/Field Validation/README.md deleted file mode 100644 index 9e5f32c701..0000000000 --- a/Client-Side Components/Client Scripts/Field Validation/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# Field valiation for Special Characters on any table - -With this onChange Client script you can validate if there are any special characters present in the input given by user in a particular field and show an error message below the field and clear the field value. -Although we have various methods to do this, it is much easier and you can customize your error message. From b12642a7142af9f3444ef10d5bdb881876c0ffbd Mon Sep 17 00:00:00 2001 From: Willem Date: Fri, 10 Oct 2025 16:22:34 +0200 Subject: [PATCH 4/4] Update readme.md Expanded and clarified the Readme. Also included in the description the updated script. --- .../Check for special characters/readme.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Specialized Areas/Regular Expressions/Check for special characters/readme.md b/Specialized Areas/Regular Expressions/Check for special characters/readme.md index 8b13789179..785c0366bc 100644 --- a/Specialized Areas/Regular Expressions/Check for special characters/readme.md +++ b/Specialized Areas/Regular Expressions/Check for special characters/readme.md @@ -1 +1,26 @@ +# Special Characters Validation (onChange Client Script) + +This script validates user input in a specific field and prevents the use of disallowed special characters. +It is designed to run as an **onChange client script** . + +## Functionality + +- When the user changes the value of a field, the script checks if the new value contains any special characters. +- If disallowed characters are found, the field is cleared and an error message is displayed to the user. +- The validation uses a regular expression that includes common special characters such as `~`, `@`, `|`, `$`, `^`, `<`, `>`, `*`, `+`, `=`, `;`, `?`, `` ` ``, `'`, `(`, `)`, `[`, and `]`. + +## How to Use + +1. Add the script as an **onChange client script** on the field you want to validate. +2. Replace the placeholder `''` in the script with the actual field name. +3. Customize the regular expression if you want to allow or block different characters. + +## Example Behavior + +- Input: `Hello@World` → ❌ Invalid → Field is cleared, error message shown. +- Input: `HelloWorld` → ✅ Valid → No action taken. + +## Notes + +- The script uses `g_form.clearValue()` to reset the field and `g_form.showErrorBox()` to display feedback.