- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2018 07:50 AM
Hi Everyone,
Does anyone here know how to allow only numeric data in a single line field? Majority, we will use it in catalog item variables so we want it to be global function and we will just call the function if we want to use it using client script. Thanks and I appreciate your help!
Best Regards,
Diane Miro
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2018
10:44 AM
- last edited on
01-30-2024
05:10 PM
by
ServiceNow
Hey Miro,
This is my script for accepting numbers only
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var regexp = /^[+]?\d*$/;
if(!regexp.test(newValue)){
alert('Please enter numeric value');
g_form.setValue('v_sec_review_unknown','');
}
}
in addition I defined "variable attributes max_length=3" to accept up to 3 digits
This is one of my sources:
You can also Refer:
Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2018
07:59 AM
- last edited on
01-30-2024
05:05 PM
by
ServiceNow
Hi Diane,
below thread will usefull to you..
ensuring a single line text field only has numbers
How to get an integer field on a catalog form
Thank you,
Vishu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2018
10:44 AM
- last edited on
01-30-2024
05:10 PM
by
ServiceNow
Hey Miro,
This is my script for accepting numbers only
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var regexp = /^[+]?\d*$/;
if(!regexp.test(newValue)){
alert('Please enter numeric value');
g_form.setValue('v_sec_review_unknown','');
}
}
in addition I defined "variable attributes max_length=3" to accept up to 3 digits
This is one of my sources:
You can also Refer:
Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2018 01:22 AM
Hello Rajesh,
Thank you so much for your help. But may I know how can I make this global so that I can only call the function names in scripts? Thank you!
Best Regards,
Diane Miro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2018 06:02 AM
Hey Miro,
Any update on this?
Would you mind please close this thread, then only this will be helpful for other community user.
thanks in advance.....!!!
If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
If you are viewing this from the community inbox you will not see the correct answer button. If so, please review How to Mark Answers Correct From Inbox View
Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke