Skip to content

Valid mobile number #1569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Client Scripts/validate phone number/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This script is triggered when the phone field changes.
It uses to validate the length of the phone number. If it exceeds the maximum length, it displays an error message and clears the field.
13 changes: 13 additions & 0 deletions Client Scripts/validate phone number/validateLength.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Client Script: Validate Length
// Table: sys_user
// Type: onChange
// Field: phone

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') return;

if (newValue.length>12) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if somebody uses spaces or dashes in the phone number? +1 (800) 123-4567 is 17 characters and is a valid format for a phone number in the US. Have you considered using a regex to test the phone number? Additionally there is a dedicated field type for phone numbers, so can you provide some context around when you would use this script instead of the field?

g_form.showFieldMsg('phone', 'Phone number should have a maximum of 12 charecters', 'error');
g_form.setValue('phone', '');
}
}
Loading