Regular expression to restrict 20 characters in single line text variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2019 03:37 AM
HI All,
I need help to build regular expression to restrict enter 20 numbers & below characters in single line text.
20 Numeric and only the special characters that include: + ( ) -
Thanks in advance.!
Thanks,
Rajashekhar Mushke
Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2019 04:02 PM
Hi try this:
^[\d ()-]{1,20}$
Thanks
Regina

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2019 11:59 PM
Hi Rajashekar,
The below script will do the required checks.
var test_string = "1234";// replace with your form variable
var regex = /^[\+\-()0-9]{0,10}$/;
var result = regex.test(test_string);
alert(result);
Also make use of madrid Variable Validation Regex.
For more details on using Variable Validation Regex check the below link.
-Satheesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2019 08:25 AM
Hi,
Please try this code for above Requirement.It's Working fine on my DEV.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var phone = g_form.getValue('phone_number');// Phone_number is my variable name
var answer = true;
var param =/^[0-9-+()]{1,15}$/;
if (!phone.match(param))
{
g_form.addErrorMessage('Only valid Phone numbers are allowed');
g_form.clearValue('phone_number');
answer = false;
}
else if (phone == /^[0-9-+()]{1,15}$/)
{
g_form.setValue('phone_number');
} else {
answer = true;
}
return answer;
}
Thanks,
Prathyusha.