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

H_9
Giga Guru

Hi Vinay,

You can write an On Change type client script, which will run on that integer type field.

In the script you can have the validation as

if (g_form.getValue('<integer_field_name>') == 10 || g_form.getValue('<integer_field_name>') == 30 || g_form.getValue('<integer_field_name>') == 40) {
g_form.showFieldMsg('<integer_field_name>','Error Message: The entered value is not allowed','error');
}

This will add the validation to the field.

Thanks. šŸ™‚

Vijaykumar K
Tera Contributor

Hi K9,

 

Thanks for your reply but as I tried , given on change  client script is not working.. it's unable to validate values and accepting the all integers although I have given 10 and 20 to be taken..

Can you please share screenshot of your client script?

 

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

Please try below logic:


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


Make sure client script is of type on Change and field selected is your integer field.

 

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