Regular expression
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2024 05:15 AM
Hi,
I need a regular expression for
"Phone number needs to meet following criteria"
"1. Starts with '+'
"2. Followed by digit 1 - 9
"3. Followed by digits 0 - 9 with / without space in between.
4. Should not have any alphabets in it.";
via OnChange client script
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2024 05:43 AM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var phonePattern = /^\+[1-9][0-9\s]*$/;
if (!phonePattern.test(newValue)) {
g_form.showFieldMsg(control.name, 'Phone number must start with + followed by a digit (1-9), and can include digits (0-9) with optional spaces.', 'error');
g_form.clearValue(control.name); // Optionally clear the invalid value
} else {
g_form.hideFieldMsg(control.name);
}
}
Not sure why asking once wasn't enough, but here again the solution.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark