Validating integer field type

Vijaykumar K
Tera Contributor

Hi All, I have a integer field type . In that I need to restrict user to enter only few values like , 10,30,40. If the user try to enter any other values it should throw error .. any one help me with these work around here . Thanks 

1 ACCEPTED SOLUTION

Hi,

Just add one more line as shown below:

 

g_form.showFieldMsg('field_name','Error Message: The entered value is not allowed','error');

g_form.clearValue('field_name'); 

// this will clear value , hope your field is mandatory so user won't be able to submit form with empty field

 

Or use same logic in on submit client script and instead of  clear value use below:

 

g_form.showFieldMsg('field_name','Error Message: The entered value is not allowed','error');

return false;

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

10 REPLIES 10

Hi,

You can modify it like below:

 

if (g_form.getValue('field_name') != 10 && g_form.getValue('field_name') != 10 && g_form.getValue('field_name') != 30 && g_form.getValue('choice_field') == 1) {
g_form.showFieldMsg('field_name','Error Message: The entered value is not allowed','error');
g_from.clearValue('field_name');
}else if(g_form.getValue('field_name') != 40 && g_form.getValue('choice_field') == 2){
g_form.showFieldMsg('field_name','Error Message: The entered value is not allowed','error');
g_from.clearValue('field_name');
}

 

 

You can mark more than one answer as correct and helpful.

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande