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. 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)) {