Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +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 `'<your_field_name>'` 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.

Original file line number Diff line number Diff line change
@@ -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 = '<your_field_name>'; // 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.');
}
}
Loading