- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 05:18 AM
Hi Developer,
I need help in validating single line text field so that end user can enter numbers from 1 to 24 only.
Regards
Tinku
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 05:46 AM
simply create variable validation regex and add the regex
then link this with your text variable and no script required
^(0?[1-9]|1[0-9]|2[0-4])\b$
1) create new from this
2) fill details as this
3) Link to that variable
Output
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 05:27 AM
client script - on change of the respective field
if(parseInt(newValue) <1 || parseInt(newValue)>24){
g_form.setValue('your field', '');
g_form.g_form.showFieldMsg('your field', 'Value must be between 1 and 24');
}
Please Mark Correct AND Helpful. Thanks
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 05:44 AM
Hi
Above script is not working at all. Can you have something else for this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 05:46 AM
Check my below working response
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 05:46 AM
simply create variable validation regex and add the regex
then link this with your text variable and no script required
^(0?[1-9]|1[0-9]|2[0-4])\b$
1) create new from this
2) fill details as this
3) Link to that variable
Output
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader