- 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 09:54 PM
Hi
Only for characters it would go something like this -
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var regexp = /^[a-zA-Z]+$/;
if(!regexp.test(newValue)) {
alert('Please enter only characters');
g_form.setValue('variable name',''); // set variable to empty
}
}
Mark correct answer and close this thread if it helps.
Regards,
Omkar Mone