File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Client-Side Components/Client Scripts/validate phone number Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ Phone Number Validation — Client Script (ServiceNow)
2+ Overview
3+
4+ This Client Script ensures that users enter their phone numbers in a strict format: (123) 456-7890.
5+ It is triggered whenever the Phone field changes and validates the input in real time.
6+
7+ If the input does not match the required format, the script:
8+
9+ Clears the invalid value.
10+
11+ Displays a field-level error message directly below the field.
12+
13+ Provides a fallback alert if field-level messaging is unavailable.
14+
15+ This script is designed to be user-friendly, dynamic, and failsafe.
16+
17+ Features
18+
19+ Validates phone numbers in the format (123) 456-7890.
20+
21+ Inline error messages appear directly below the field, avoiding top-of-page clutter.
22+
23+ Clears invalid input to prevent incorrect data submission.
24+
25+ Works dynamically for any phone field with minimal configuration.
26+
27+ Provides fallback alert for environments where inline messages are unavailable.
28+
29+ Usage Instructions
30+ 1 . Create the Client Script
31+
32+ Navigate to System Definition → Client Scripts.
33+
34+ Click New to create a client script.
35+
36+ 2 . Configure the Script
37+
38+ Name: Phone Number Validation
39+
40+ Table: sys_user
41+
42+ Type: onChange
43+
44+ Field: phone
45+
46+ Active: Checked
You can’t perform that action at this time.
0 commit comments