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 12:14 PM
Use can just use length to get the count the digits, and to check if all of them are numbers use isNaN
val.length // count
isNaN(val) // true if all digits else false
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 12:50 PM
HI
where do I set that up?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2022 01:34 AM
in your onChange client script,
if (isLoading || newValue == '') {
return;
}
var val = g_form.getValue("your_field_name");
if(val.length != 10)
alert("input lenght should be 10");
else if(isNaN(val)){
alert("input should be number");
}
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 12:16 PM
Hi Navneet,
You can try below onChange Client script for number field
var number = g_form.getValue('field_name'); // add number field value
var check = /^[0-9]{10}/;
var result = number.match(check);
if(result==true)
{ g_form.setValue('field_name', 'number'); }
else
{ alert("Please make sure that the number you provide is 10 digits long"); }