Skip to content

Commit a7fc6d3

Browse files
authored
Strong username validation script (#1428)
* Script.js * readme.md
1 parent 77863c2 commit a7fc6d3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function onSubmit() {
2+
// Get the username value from the field
3+
var username = g_form.getValue('username'); // Change 'username' to your field name
4+
5+
// Define the regex pattern for a strong username
6+
var usernamePattern = /^[a-zA-Z][a-zA-Z0-9]{5,}$/;
7+
8+
// Validate the username against the pattern
9+
if (!usernamePattern.test(username)) {
10+
// Display an error message if validation fails
11+
g_form.showFieldMsg('username', 'Username must start with a letter, be at least 6 characters long, and contain only letters and numbers.', 'error');
12+
return false; // Prevent form submission
13+
}
14+
15+
return true; // Allow form submission if validation passes
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Description of the Strong Username Validation Script
2+
Purpose
3+
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.
4+
5+
Validation Criteria
6+
The username must:
7+
Start with a letter: The first character of the username must be an alphabetic character (a-z or A-Z).
8+
Be at least 6 characters long: The username must contain a minimum of six characters.
9+
Contain only letters and numbers: The username can only include alphabetic characters and digits (0-9).

0 commit comments

Comments
 (0)