From 70b17289b0e8fc9c0e38b2e9cf18366482af4bad Mon Sep 17 00:00:00 2001 From: Ravi Gaurav Date: Sat, 4 Oct 2025 21:08:11 +0530 Subject: [PATCH 01/12] Create phoneNumberValidation.js This function validates the phone number entered by the user. If it is not in the correct format (Indian mobile number with optional 0/91 prefix), the form will not be submitted. --- .../Phone Number Validation /phoneNumberValidation.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Client-Side Components/Client Scripts/Phone Number Validation /phoneNumberValidation.js diff --git a/Client-Side Components/Client Scripts/Phone Number Validation /phoneNumberValidation.js b/Client-Side Components/Client Scripts/Phone Number Validation /phoneNumberValidation.js new file mode 100644 index 0000000000..943e3409cf --- /dev/null +++ b/Client-Side Components/Client Scripts/Phone Number Validation /phoneNumberValidation.js @@ -0,0 +1,8 @@ +function onSubmit() { + +var phone=g_form.getValue('phone_number_field');//09898989 +var pregex=/(0|91)?[6-9][0-9]{9}/; +if(!pregex.test(phone)){ + alert("Enter correct phone number"); + return false; +} From 2c4f938c99c614ead9c465540bb6369da021a4c6 Mon Sep 17 00:00:00 2001 From: Ravi Gaurav Date: Sat, 4 Oct 2025 21:13:00 +0530 Subject: [PATCH 02/12] Create README.md Readme file is for instruction or usages of code. --- .../Phone Number Validation /README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Client-Side Components/Client Scripts/Phone Number Validation /README.md diff --git a/Client-Side Components/Client Scripts/Phone Number Validation /README.md b/Client-Side Components/Client Scripts/Phone Number Validation /README.md new file mode 100644 index 0000000000..dc043456b6 --- /dev/null +++ b/Client-Side Components/Client Scripts/Phone Number Validation /README.md @@ -0,0 +1,14 @@ +We are building a form in ServiceNow where a user must enter their phone number. +The requirement is that only valid Indian mobile numbers should be accepted. A valid number should: + +Optionally start with 0 or 91 + +Be exactly 10 digits long + +Start with digits 6, 7, 8, or 9 + +If the user enters anything invalid, the form should not be submitted, and an error message should be shown. + +g_form.getValue → gets the phone field value. +Regex → allows numbers like 9876543210, 0919876543210, 919876543210. +Validation → If the value is invalid, shows alert and blocks submission. From a9cd635176acba8b3e24c6cb71bca92e392bc96f Mon Sep 17 00:00:00 2001 From: Ravi Gaurav Date: Sat, 4 Oct 2025 21:27:26 +0530 Subject: [PATCH 03/12] Delete Client-Side Components/Client Scripts/Phone Number Validation directory --- .../Phone Number Validation /README.md | 14 -------------- .../phoneNumberValidation.js | 8 -------- 2 files changed, 22 deletions(-) delete mode 100644 Client-Side Components/Client Scripts/Phone Number Validation /README.md delete mode 100644 Client-Side Components/Client Scripts/Phone Number Validation /phoneNumberValidation.js diff --git a/Client-Side Components/Client Scripts/Phone Number Validation /README.md b/Client-Side Components/Client Scripts/Phone Number Validation /README.md deleted file mode 100644 index dc043456b6..0000000000 --- a/Client-Side Components/Client Scripts/Phone Number Validation /README.md +++ /dev/null @@ -1,14 +0,0 @@ -We are building a form in ServiceNow where a user must enter their phone number. -The requirement is that only valid Indian mobile numbers should be accepted. A valid number should: - -Optionally start with 0 or 91 - -Be exactly 10 digits long - -Start with digits 6, 7, 8, or 9 - -If the user enters anything invalid, the form should not be submitted, and an error message should be shown. - -g_form.getValue → gets the phone field value. -Regex → allows numbers like 9876543210, 0919876543210, 919876543210. -Validation → If the value is invalid, shows alert and blocks submission. diff --git a/Client-Side Components/Client Scripts/Phone Number Validation /phoneNumberValidation.js b/Client-Side Components/Client Scripts/Phone Number Validation /phoneNumberValidation.js deleted file mode 100644 index 943e3409cf..0000000000 --- a/Client-Side Components/Client Scripts/Phone Number Validation /phoneNumberValidation.js +++ /dev/null @@ -1,8 +0,0 @@ -function onSubmit() { - -var phone=g_form.getValue('phone_number_field');//09898989 -var pregex=/(0|91)?[6-9][0-9]{9}/; -if(!pregex.test(phone)){ - alert("Enter correct phone number"); - return false; -} From 2febfa6dcc8586a7573d53c6ae7cdc5c312ce633 Mon Sep 17 00:00:00 2001 From: Ravi Gaurav Date: Sat, 4 Oct 2025 21:29:21 +0530 Subject: [PATCH 04/12] Create README.MD This File contains instructions or usages of script --- .../Phone Number Validation/README.MD | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Client-Side Components/Client Scripts/Phone Number Validation/README.MD diff --git a/Client-Side Components/Client Scripts/Phone Number Validation/README.MD b/Client-Side Components/Client Scripts/Phone Number Validation/README.MD new file mode 100644 index 0000000000..dc043456b6 --- /dev/null +++ b/Client-Side Components/Client Scripts/Phone Number Validation/README.MD @@ -0,0 +1,14 @@ +We are building a form in ServiceNow where a user must enter their phone number. +The requirement is that only valid Indian mobile numbers should be accepted. A valid number should: + +Optionally start with 0 or 91 + +Be exactly 10 digits long + +Start with digits 6, 7, 8, or 9 + +If the user enters anything invalid, the form should not be submitted, and an error message should be shown. + +g_form.getValue → gets the phone field value. +Regex → allows numbers like 9876543210, 0919876543210, 919876543210. +Validation → If the value is invalid, shows alert and blocks submission. From 4345e3c3306157334fc1c27193d11c298510a0f5 Mon Sep 17 00:00:00 2001 From: Ravi Gaurav Date: Sat, 4 Oct 2025 21:30:09 +0530 Subject: [PATCH 05/12] Add files via upload --- .../Phone Number Validation/phoneNumberValidation.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Client-Side Components/Client Scripts/Phone Number Validation/phoneNumberValidation.js diff --git a/Client-Side Components/Client Scripts/Phone Number Validation/phoneNumberValidation.js b/Client-Side Components/Client Scripts/Phone Number Validation/phoneNumberValidation.js new file mode 100644 index 0000000000..943e3409cf --- /dev/null +++ b/Client-Side Components/Client Scripts/Phone Number Validation/phoneNumberValidation.js @@ -0,0 +1,8 @@ +function onSubmit() { + +var phone=g_form.getValue('phone_number_field');//09898989 +var pregex=/(0|91)?[6-9][0-9]{9}/; +if(!pregex.test(phone)){ + alert("Enter correct phone number"); + return false; +} From 06dd568fdecacf379fbd84185d474272a3d79443 Mon Sep 17 00:00:00 2001 From: Ravi Gaurav Date: Sat, 4 Oct 2025 21:59:02 +0530 Subject: [PATCH 06/12] Create GreetingMessage.js We want to display a friendly greeting message to the user whenever they open the Incident form in ServiceNow. The greeting should change depending on the time of the day. --- .../Dynamic Greeting Based on Time/GreetingMessage.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/GreetingMessage.js diff --git a/Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/GreetingMessage.js b/Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/GreetingMessage.js new file mode 100644 index 0000000000..c3fafb6373 --- /dev/null +++ b/Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/GreetingMessage.js @@ -0,0 +1,7 @@ + +// Type: onLoad | Table: incident +function onLoad() { + var hr = new Date().getHours(); + var msg = (hr < 12) ? "Good Morning!" : (hr < 18) ? "Good Afternoon!" : "Good Evening!"; + g_form.addInfoMessage(msg + " Please provide the details of your issue."); +} From deab9c2bc4c51a2f0a9406335180759c60d5063b Mon Sep 17 00:00:00 2001 From: Ravi Gaurav Date: Sat, 4 Oct 2025 22:00:57 +0530 Subject: [PATCH 07/12] Create README.MD This file provide the instructions or usages of the code. --- .../Dynamic Greeting Based on Time/README.MD | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/README.MD diff --git a/Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/README.MD b/Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/README.MD new file mode 100644 index 0000000000..ed72ca3792 --- /dev/null +++ b/Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/README.MD @@ -0,0 +1,18 @@ +How it Code work Step by Step + +Trigger: +This script runs onLoad (when the Incident form is opened). +It only applies to the Incident table. +Get current hour: +new Date().getHours() → fetches the current system hour (0–23 format). +Example: 9 = 9 AM, 15 = 3 PM, 20 = 8 PM. +Condition (Ternary Operator): +If hour is < 12 → Morning +Else if hour < 18 → Afternoon +Else → Evening +Add Info Message: +g_form.addInfoMessage(...) shows a friendly banner on top of the form. +Example output: +Morning (9 AM) → “Good Morning! Please provide the details of your issue.” + +Evening (8 PM) → “Good Evening! Please provide the details of your issue.” From 24c52a392f13e16c591a51a81b271afb8de9bda8 Mon Sep 17 00:00:00 2001 From: Ravi Gaurav Date: Sat, 4 Oct 2025 22:21:32 +0530 Subject: [PATCH 08/12] Delete Client-Side Components/Client Scripts/Phone Number Validation directory --- .../Phone Number Validation/README.MD | 14 -------------- .../phoneNumberValidation.js | 8 -------- 2 files changed, 22 deletions(-) delete mode 100644 Client-Side Components/Client Scripts/Phone Number Validation/README.MD delete mode 100644 Client-Side Components/Client Scripts/Phone Number Validation/phoneNumberValidation.js diff --git a/Client-Side Components/Client Scripts/Phone Number Validation/README.MD b/Client-Side Components/Client Scripts/Phone Number Validation/README.MD deleted file mode 100644 index dc043456b6..0000000000 --- a/Client-Side Components/Client Scripts/Phone Number Validation/README.MD +++ /dev/null @@ -1,14 +0,0 @@ -We are building a form in ServiceNow where a user must enter their phone number. -The requirement is that only valid Indian mobile numbers should be accepted. A valid number should: - -Optionally start with 0 or 91 - -Be exactly 10 digits long - -Start with digits 6, 7, 8, or 9 - -If the user enters anything invalid, the form should not be submitted, and an error message should be shown. - -g_form.getValue → gets the phone field value. -Regex → allows numbers like 9876543210, 0919876543210, 919876543210. -Validation → If the value is invalid, shows alert and blocks submission. diff --git a/Client-Side Components/Client Scripts/Phone Number Validation/phoneNumberValidation.js b/Client-Side Components/Client Scripts/Phone Number Validation/phoneNumberValidation.js deleted file mode 100644 index 943e3409cf..0000000000 --- a/Client-Side Components/Client Scripts/Phone Number Validation/phoneNumberValidation.js +++ /dev/null @@ -1,8 +0,0 @@ -function onSubmit() { - -var phone=g_form.getValue('phone_number_field');//09898989 -var pregex=/(0|91)?[6-9][0-9]{9}/; -if(!pregex.test(phone)){ - alert("Enter correct phone number"); - return false; -} From 0bf63e5593f2b26f5bcf53635f45fea9130f670a Mon Sep 17 00:00:00 2001 From: Ravi Gaurav Date: Sat, 4 Oct 2025 23:36:37 +0530 Subject: [PATCH 09/12] Create password.js This Script Include validates the strength of a password. It can be used in scenarios like: User self-registration (ensuring strong password before allowing submission). Custom portal forms (when users create accounts or update passwords). Service Desk workflows (where support staff reset user accounts and must set secure passwords). --- .../Password Strength Checker/password.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Server-Side Components/Script Includes/Password Strength Checker/password.js diff --git a/Server-Side Components/Script Includes/Password Strength Checker/password.js b/Server-Side Components/Script Includes/Password Strength Checker/password.js new file mode 100644 index 0000000000..0c11ef858d --- /dev/null +++ b/Server-Side Components/Script Includes/Password Strength Checker/password.js @@ -0,0 +1,31 @@ +// Class definition +var PasswordUtil = Class.create(); +PasswordUtil.prototype = { + initialize: function() {}, + + /** + * checkStrength + * @param {String} pwd - The password string to evaluate + * @return {String} result - Returns "Strong Password" or "Weak Password" + */ + checkStrength: function(pwd) { + // If password is empty/null, return message + if (!pwd) return "Empty password!"; + + // Rules for strong password: + // 1. At least 8 characters + // 2. At least one uppercase letter + // 3. At least one lowercase letter + // 4. At least one number + // 5. At least one special character + var strong = pwd.length >= 8 && + /[A-Z]/.test(pwd) && // has uppercase + /[a-z]/.test(pwd) && // has lowercase + /[0-9]/.test(pwd) && // has number + /[^A-Za-z0-9]/.test(pwd); // has special char + + return strong ? "Strong Password" : "Weak Password"; + }, + + type: 'PasswordUtil' +}; From 7f46c0be1155276114114db03989e35e6109f337 Mon Sep 17 00:00:00 2001 From: Ravi Gaurav Date: Sat, 4 Oct 2025 23:38:56 +0530 Subject: [PATCH 10/12] Create README.MD This Readme includes code usage of ServiceNow Password Strength Checker --- .../Password Strength Checker/README.MD | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Server-Side Components/Script Includes/Password Strength Checker/README.MD diff --git a/Server-Side Components/Script Includes/Password Strength Checker/README.MD b/Server-Side Components/Script Includes/Password Strength Checker/README.MD new file mode 100644 index 0000000000..8bef91c8b6 --- /dev/null +++ b/Server-Side Components/Script Includes/Password Strength Checker/README.MD @@ -0,0 +1,17 @@ +This repository contains a ServiceNow Script Include + Client Script demo for enforcing password strength during user registration or password reset processes. +Overview + +The goal is to ensure that any password set in ServiceNow (e.g., through a Catalog Item or custom form) follows strong security rules: +At least 8 characters +At least 1 uppercase letter +At least 1 lowercase letter +At least 1 number +At least 1 special character +If the rules are not met, the system flags the password as Weak Password. + +Example : +Imagine you build a User Registration Catalog Item where a field Proposed Password is entered by the user. +On change of this field, the Client Script runs. +It calls the PasswordUtil Script Include. +If the password is weak, the form shows an inline error message, preventing weak password submissions. +This ensures consistent security enforcement across ServiceNow forms. From b3db1e2b33a273a23edd4b3716c7b8e82bef1ced Mon Sep 17 00:00:00 2001 From: Ravi Gaurav Date: Sat, 4 Oct 2025 23:50:27 +0530 Subject: [PATCH 11/12] Delete Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/GreetingMessage.js --- .../Dynamic Greeting Based on Time/GreetingMessage.js | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/GreetingMessage.js diff --git a/Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/GreetingMessage.js b/Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/GreetingMessage.js deleted file mode 100644 index c3fafb6373..0000000000 --- a/Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/GreetingMessage.js +++ /dev/null @@ -1,7 +0,0 @@ - -// Type: onLoad | Table: incident -function onLoad() { - var hr = new Date().getHours(); - var msg = (hr < 12) ? "Good Morning!" : (hr < 18) ? "Good Afternoon!" : "Good Evening!"; - g_form.addInfoMessage(msg + " Please provide the details of your issue."); -} From 8b0cd2df002d64ade7185118de5f2c61136f73bb Mon Sep 17 00:00:00 2001 From: Ravi Gaurav Date: Sat, 4 Oct 2025 23:50:51 +0530 Subject: [PATCH 12/12] Delete Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/README.MD --- .../Dynamic Greeting Based on Time/README.MD | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/README.MD diff --git a/Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/README.MD b/Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/README.MD deleted file mode 100644 index ed72ca3792..0000000000 --- a/Client-Side Components/Client Scripts/Dynamic Greeting Based on Time/README.MD +++ /dev/null @@ -1,18 +0,0 @@ -How it Code work Step by Step - -Trigger: -This script runs onLoad (when the Incident form is opened). -It only applies to the Incident table. -Get current hour: -new Date().getHours() → fetches the current system hour (0–23 format). -Example: 9 = 9 AM, 15 = 3 PM, 20 = 8 PM. -Condition (Ternary Operator): -If hour is < 12 → Morning -Else if hour < 18 → Afternoon -Else → Evening -Add Info Message: -g_form.addInfoMessage(...) shows a friendly banner on top of the form. -Example output: -Morning (9 AM) → “Good Morning! Please provide the details of your issue.” - -Evening (8 PM) → “Good Evening! Please provide the details of your issue.”