- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2019 06:13 PM
Hi,
I have an onChange client script that is not working the way it should. I am trying to notify users that the maximum numbers allowed is 10 digits (if they are trying to enter more than 10). I also want the variable to allow only integer. Below is what i have but its not working properly.
var parsed = g_form.getIntValue("variable_name");
//if "Not a Number", clear the parsed value
if (isNaN(parsed)){
parsed = "";
}
if (parsed != newValue) {
alert("Please enter a valid integer number ");
g_form.setValue("variable_name", parsed);
//if more than 10
if(parseInt(newValue) > 10){
alert(getMessage("10 digits max"));
g_form.setValue("variable_name", '');
return false;
}
}
}
Thank you.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2019 07:12 PM
You can try onchange script provided by Kunal or
You can use variable attributes to set the max_length on the variable to stop user from entering more than 10 characters. Then, you use on change client script to validate entered characters are integers only.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var regexp = /^([0-9]+[0-9])/;
if(!regexp.test(newValue)) {
alert('Please enter a 10 digit number');
g_form.setValue('variable name',''); // set variable to empty
}
}
If I answered your question, please mark Correct/Helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2019 06:22 PM
Put the below code in your onchange client script
var regex= /^[0-9]*$/;
if(!regex.test(newValue) || (newValue.length <= 9) )// adjust your digits.
{
alert('please enter only digits and min length should be 10 ');
g_form.setValue('variable_name', ''); // Blank Out the field
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2019 06:55 PM
Hi Bruce,
Refer Below script
var isnum = /^\d+$/.test(g_form.getValue('variable_name'));
//alert("isnum: " + isnum);
if (!isnum) {
alert('variable_name should be only numbers.');
return false;
} else {
if (g_form.getValue('vaiable_name').length > 10) {
alert('variable_name should not contain more than 10 digits.');
return false;
}
}
}
Please Mark Correct/Helpful if it Help you.
Regard,
Kunal.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2019 07:12 PM
You can try onchange script provided by Kunal or
You can use variable attributes to set the max_length on the variable to stop user from entering more than 10 characters. Then, you use on change client script to validate entered characters are integers only.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var regexp = /^([0-9]+[0-9])/;
if(!regexp.test(newValue)) {
alert('Please enter a 10 digit number');
g_form.setValue('variable name',''); // set variable to empty
}
}
If I answered your question, please mark Correct/Helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2019 07:30 PM
This worked well.
Thank you all for your help.