How do you limit a variable to 10digits?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 12:06 PM
Hi, The requirement is> minimum of 10 digits is required for a variable.
Is this the correct script?
Here is the script. I created a on change script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var val = g_form.getValue('Facility_npi');
var pattern = /\d{10}/;
if (pattern.test(val))
alert('looks like 10 digits');
else
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 01:15 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 08:25 PM
Hi Navneet,
check below i have tried on my instance and its working fine
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var num = g_form.getValue('number'); // add number field value
var pattern = /^[0-9]{10}$/;
if (pattern.test(num)) {
g_form.setValue('number', num);
} else {
alert("Please make sure that the number you provide is 10 digits long");
g_form.clearValue('number');
}
}
Output :

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2022 11:02 AM
Hi Navneet,
If my response with output is worked for you, mark it as correct, so it will be useful for future readers

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 01:34 PM
Since you have already used Validation regex as number all you need is a check for length.
Try below
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var val = g_form.getValue('Facility_npi');
var lengthis = val.length;
if (lengthis > 9) { //do nothing
} else {
alert('Enter more than 10 digits');
g_form.getValue('Facility_npi', '');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2022 09:27 AM
Jaspal, This worked also. thak you