From 70b17289b0e8fc9c0e38b2e9cf18366482af4bad Mon Sep 17 00:00:00 2001 From: Ravi Gaurav Date: Sat, 4 Oct 2025 21:08:11 +0530 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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; +}