Skip to content

Commit 6a6d963

Browse files
Validate phone format 123 234 5678 no regex (#2375)
* Create Validate PhNo.js * Create Readme.md * Rename Validate PhNo.js to validate_phone_format_(123)_456-7890_no_regex.js.js * Update validate_phone_format_(123)_456-7890_no_regex.js.js Validates a field to ensure no spaces and enforces the phone number format (123) 456-7890 without using regex. Displays an inline error message below the field and clears invalid input for strict, user-friendly data entry.
1 parent 829c10f commit 6a6d963

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Phone Number Validation — Client Script
2+
Overview
3+
4+
This Client Script validates that users enter their phone numbers in the strict format: (123) 456-7890.
5+
6+
It is triggered whenever the Phone field changes on a sys_user record. If the input does not match the required format, the script:
7+
8+
Displays an inline error message directly below the field.
9+
10+
Clears the invalid input so the user can re-enter the correct value.
11+
12+
This script is designed to be dynamic, simple, and user-friendly.
13+
14+
Features
15+
16+
Ensures phone numbers follow the exact format (123) 456-7890.
17+
18+
Provides immediate feedback via field-level error messages.
19+
20+
Clears invalid entries automatically to prevent submission errors.
21+
22+
Works on Classic UI forms and provides clear messaging to the user.
23+
24+
Usage Instructions
25+
1. Create the Client Script
26+
27+
Navigate to System Definition → Client Scripts.
28+
29+
Click New to create a client script.
30+
31+
2. Configure the Script
32+
33+
Name: Phone Number Validation
34+
35+
Table: sys_user
36+
37+
Type: onChange
38+
39+
Field: phone
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function onChange(control, oldValue, newValue, isLoading) {
2+
if (isLoading || !newValue) return;
3+
4+
var fieldName = control.name;
5+
6+
// Split the string
7+
var area = newValue.substring(1, 4);
8+
var firstThree = newValue.substring(6, 9);
9+
var lastFour = newValue.substring(10, 14);
10+
11+
if (
12+
newValue[0] !== '(' || newValue[4] !== ')' || newValue[5] !== ' ' || newValue[9] !== '-' ||
13+
isNaN(parseInt(area)) || isNaN(parseInt(firstThree)) || isNaN(parseInt(lastFour))
14+
) {
15+
g_form.showFieldMsg(
16+
fieldName,
17+
'Phone Number must be in the format (123) 456-7890',
18+
'error',
19+
false
20+
);
21+
g_form.setValue(fieldName, '');
22+
}
23+
}

0 commit comments

Comments
 (0)