Is there a client script to ensure that a field only contains numbers?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2017 10:19 AM
I need a client script for a field that should contain an accounting code that should only be numeric. People sometimes put, "I don't know what this is"....and we want them to find there accounting code for their department. The field should only accept numbers. Does anyone have a client script for this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2017 10:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2017 10:25 AM
Hi,
You can write onChange client script on the field to validate for number.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(isNan(newValue)){
g_form.setValue('field_name', ''); //This should be your number field name
g_form.addInfoMessage('You should enter a number');
}
}
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2017 10:27 AM
This should do
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//check only numbers
var pattern = /[0-9]/;
if(!pattern.test(newValue)){
alert('enter only number');
g_form.setValue('u_account_code', ''); //u_account_code is the field name
}
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 05:17 AM
The provided code working as expected only.