From 07a4fd6d6482be05b879484e3566e124cad0b424 Mon Sep 17 00:00:00 2001 From: Willem Date: Sun, 12 Oct 2025 15:00:45 +0200 Subject: [PATCH 1/2] Update and rename Script.js to Script.js Moved to Regex folder and added comment to explain the Regex. --- .../Regular Expressions/Username validation}/Script.js | 8 ++++++++ 1 file changed, 8 insertions(+) rename {Client-Side Components/Catalog Client Script/Strong Username Validation Script => Specialized Areas/Regular Expressions/Username validation}/Script.js (69%) diff --git a/Client-Side Components/Catalog Client Script/Strong Username Validation Script/Script.js b/Specialized Areas/Regular Expressions/Username validation/Script.js similarity index 69% rename from Client-Side Components/Catalog Client Script/Strong Username Validation Script/Script.js rename to Specialized Areas/Regular Expressions/Username validation/Script.js index 1189eac294..daff495f5b 100644 --- a/Client-Side Components/Catalog Client Script/Strong Username Validation Script/Script.js +++ b/Specialized Areas/Regular Expressions/Username validation/Script.js @@ -4,6 +4,14 @@ function onSubmit() { // Define the regex pattern for a strong username var usernamePattern = /^[a-zA-Z][a-zA-Z0-9]{5,}$/; + + // Regex explanation: + // ^ : Start of string + // [a-zA-Z] : First character must be a letter + // [a-zA-Z0-9] : Remaining characters can be letters or digits + // {5,} : At least 5 more characters (total minimum length = 6) + // $ : End of string + // Validate the username against the pattern if (!usernamePattern.test(username)) { From 8c1a3638e3f4099b7e809d64d66b58804164d824 Mon Sep 17 00:00:00 2001 From: Willem Date: Sun, 12 Oct 2025 15:04:15 +0200 Subject: [PATCH 2/2] Update and rename README.md to README.md Updated the readme to be more descriptive: described the criteria the script evaluates, and added how to use the script. --- .../Strong Username Validation Script/README.md | 9 --------- .../Regular Expressions/Username validation/README.md | 10 ++++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 Client-Side Components/Catalog Client Script/Strong Username Validation Script/README.md create mode 100644 Specialized Areas/Regular Expressions/Username validation/README.md diff --git a/Client-Side Components/Catalog Client Script/Strong Username Validation Script/README.md b/Client-Side Components/Catalog Client Script/Strong Username Validation Script/README.md deleted file mode 100644 index 3ae51d1735..0000000000 --- a/Client-Side Components/Catalog Client Script/Strong Username Validation Script/README.md +++ /dev/null @@ -1,9 +0,0 @@ -Description of the Strong Username Validation Script -Purpose -The script is designed to validate a username entered by the user in a ServiceNow catalog item form. It ensures that the username adheres to specific criteria before the form can be successfully submitted. - -Validation Criteria -The username must: -Start with a letter: The first character of the username must be an alphabetic character (a-z or A-Z). -Be at least 6 characters long: The username must contain a minimum of six characters. -Contain only letters and numbers: The username can only include alphabetic characters and digits (0-9). diff --git a/Specialized Areas/Regular Expressions/Username validation/README.md b/Specialized Areas/Regular Expressions/Username validation/README.md new file mode 100644 index 0000000000..a24ead6566 --- /dev/null +++ b/Specialized Areas/Regular Expressions/Username validation/README.md @@ -0,0 +1,10 @@ +## Strong Username Validation Script +This script validates a username entered in a ServiceNow catalog item form. It prevents form submission if the username does not meet the required format. + +### Validation Criteria +The username must start with a letter (a–z or A–Z). +It must be at least 6 characters long. +It can only contain letters and numbers. + +## Usage +Add the script as an onSubmit client script in the catalog item. If the username is invalid, an error message is shown and the form is not submitted.