diff --git a/Client-Side Components/Client Scripts/validate phone number/Readme.md b/Client-Side Components/Client Scripts/validate phone number/Readme.md new file mode 100644 index 0000000000..5f47923199 --- /dev/null +++ b/Client-Side Components/Client Scripts/validate phone number/Readme.md @@ -0,0 +1,39 @@ +Phone Number Validation — Client Script +Overview + +This Client Script validates that users enter their phone numbers in the strict format: (123) 456-7890. + +It is triggered whenever the Phone field changes on a sys_user record. If the input does not match the required format, the script: + +Displays an inline error message directly below the field. + +Clears the invalid input so the user can re-enter the correct value. + +This script is designed to be dynamic, simple, and user-friendly. + +Features + +Ensures phone numbers follow the exact format (123) 456-7890. + +Provides immediate feedback via field-level error messages. + +Clears invalid entries automatically to prevent submission errors. + +Works on Classic UI forms and provides clear messaging to the user. + +Usage Instructions +1. Create the Client Script + +Navigate to System Definition → Client Scripts. + +Click New to create a client script. + +2. Configure the Script + +Name: Phone Number Validation + +Table: sys_user + +Type: onChange + +Field: phone diff --git a/Client-Side Components/Client Scripts/validate phone number/validate_phone_format_(123)_456-7890_no_regex.js.js b/Client-Side Components/Client Scripts/validate phone number/validate_phone_format_(123)_456-7890_no_regex.js.js new file mode 100644 index 0000000000..9a293deb03 --- /dev/null +++ b/Client-Side Components/Client Scripts/validate phone number/validate_phone_format_(123)_456-7890_no_regex.js.js @@ -0,0 +1,23 @@ +function onChange(control, oldValue, newValue, isLoading) { + if (isLoading || !newValue) return; + + var fieldName = control.name; + + // Split the string + var area = newValue.substring(1, 4); + var firstThree = newValue.substring(6, 9); + var lastFour = newValue.substring(10, 14); + + if ( + newValue[0] !== '(' || newValue[4] !== ')' || newValue[5] !== ' ' || newValue[9] !== '-' || + isNaN(parseInt(area)) || isNaN(parseInt(firstThree)) || isNaN(parseInt(lastFour)) + ) { + g_form.showFieldMsg( + fieldName, + 'Phone Number must be in the format (123) 456-7890', + 'error', + false + ); + g_form.setValue(fieldName, ''); + } +}