How do you limit a variable to 10digits?

Navneet3
Tera Expert

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

find_real_file.png

 

 

find_real_file.png

 

 

 

15 REPLIES 15

Aman Kumar S
Kilo Patron

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

 

Best Regards
Aman Kumar

HI

where do I set that up?

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");
}
Best Regards
Aman Kumar

Chetan Mahajan
Kilo Sage
Kilo Sage

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"); }