- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2019 11:00 PM
Hi All,
Can any one please assist me to write a regex to validate if value entered is in between 5 to 1000.
Tried few things but it's not working in script.
Many thanks!
-Ruchi
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2019 10:56 PM
Hi Ruchi,
If you want to use RegEx to validate those limits you can try:
var pattern = /^([5-9]|[1-9][0-9]|[1-9][0-9][0-9]|1000)$/g;
alert(pattern.test("999"));
Tried it for few combinations, seems to be working fine. Try that out and see if it works for you.
Hope this helps!
Cheers,
Manish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2019 10:52 PM
try this
var pattern = /^([5][555]{0,2}|1000)$/; it will allow 5,555,1000
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2019 11:12 PM
Hi Ruchi,
why you want to use regex if you can simply compare it
if(value >5 && value < 1000){
// ok
}
else{
// invalid
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
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
‎08-01-2019 11:32 PM
Hi Ankur,
Thanks for the response.
Initially i tried this but as part of best practices Regex was expected in review.
Regards,
Ruchi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2019 11:54 PM
Hi Ruchi,
yes it is good practice to use regex for complex calculation but for simple you can use the comparison itself
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
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
‎08-06-2019 09:58 PM
Hi Ankur,
I noticed this is working fine but it's not checking for value if it is digit or not. Because of which the field is accepting alphabets as well.
-Ruchi