From 9d0508bbbcd4581c5a2398d4517eb5428b34bc98 Mon Sep 17 00:00:00 2001 From: Divya <165976969+divyajetti9@users.noreply.github.com> Date: Mon, 13 Oct 2025 13:11:41 -0500 Subject: [PATCH 1/2] README.md --- .../Email & PhNo Validation/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Client-Side Components/Catalog Client Script/Email & PhNo Validation/README.md diff --git a/Client-Side Components/Catalog Client Script/Email & PhNo Validation/README.md b/Client-Side Components/Catalog Client Script/Email & PhNo Validation/README.md new file mode 100644 index 0000000000..53f9f1aa7b --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Email & PhNo Validation/README.md @@ -0,0 +1,11 @@ +This script validates the email and phone number fields entered by the user in a ServiceNow catalog item form. +It ensures that the email follows a valid format and the phone number is numeric with exactly 10 digits. + + +**Email Requirements:** +Must contain “@” and a valid domain (e.g., example.com). +No spaces or invalid characters allowed. + +**Phone Number Requirements:** +Must contain exactly 10 digits. +Only numeric values allowed (no letters or special characters). From 638ca0c8fc12cf73c4be80c360634058e8181892 Mon Sep 17 00:00:00 2001 From: Divya <165976969+divyajetti9@users.noreply.github.com> Date: Mon, 13 Oct 2025 13:13:25 -0500 Subject: [PATCH 2/2] script.js --- .../Email & PhNo Validation/script.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Client-Side Components/Catalog Client Script/Email & PhNo Validation/script.js diff --git a/Client-Side Components/Catalog Client Script/Email & PhNo Validation/script.js b/Client-Side Components/Catalog Client Script/Email & PhNo Validation/script.js new file mode 100644 index 0000000000..70fbda4fdd --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Email & PhNo Validation/script.js @@ -0,0 +1,23 @@ +function onSubmit() { + // Get the field values + var email = g_form.getValue('email'); + var phone = g_form.getValue('phone_number'); + + // Define validation patterns + var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + var phonePattern = /^\d{10}$/; + + // Validate email format + if (!emailPattern.test(email)) { + g_form.showFieldMsg('email', 'Please enter a valid email address (e.g., user@example.com).', 'error'); + return false; // Prevent form submission + } + + // Validate phone number + if (!phonePattern.test(phone)) { + g_form.showFieldMsg('phone_number', 'Phone number must be exactly 10 digits and contain only numbers.', 'error'); + return false; // Prevent form submission + } + + return true; // Allow form submission if all validations pass +}