Skip to content

Commit e5df68b

Browse files
authored
Move/strong username regex (#2070)
* Update and rename Script.js to Script.js Moved to Regex folder and added comment to explain the Regex. * 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.
1 parent c72358b commit e5df68b

File tree

3 files changed

+18
-9
lines changed
  • Client-Side Components/Catalog Client Script/Strong Username Validation Script
  • Specialized Areas/Regular Expressions/Username validation

3 files changed

+18
-9
lines changed

Client-Side Components/Catalog Client Script/Strong Username Validation Script/README.md

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Strong Username Validation Script
2+
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.
3+
4+
### Validation Criteria
5+
The username must start with a letter (a–z or A–Z).
6+
It must be at least 6 characters long.
7+
It can only contain letters and numbers.
8+
9+
## Usage
10+
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.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ function onSubmit() {
44

55
// Define the regex pattern for a strong username
66
var usernamePattern = /^[a-zA-Z][a-zA-Z0-9]{5,}$/;
7+
8+
// Regex explanation:
9+
// ^ : Start of string
10+
// [a-zA-Z] : First character must be a letter
11+
// [a-zA-Z0-9] : Remaining characters can be letters or digits
12+
// {5,} : At least 5 more characters (total minimum length = 6)
13+
// $ : End of string
14+
715

816
// Validate the username against the pattern
917
if (!usernamePattern.test(username)) {

0 commit comments

Comments
 (0)