- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2022 02:08 AM
Hello Everyone,
I'm having a hard time creating a regex validation to accept 4 integers from 0 to 2000. Below is my current onChange client script. Currently, it's not working. It doesn't accept anything. Can anyone help me with this? Thank you.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var regexp = /^\d{4}$/;
if (!regexp.test(newValue) && newValue != '2000' )
{
g_form.clearValue('unit_quantity');
g_form.showFieldMsg('unit_quantity', 'This field should contain only numbers - with a limit to 2000', 'error');
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2022 03:09 AM
Hey,
Use below regular expression:
\b([0-9]|[0-9][0-9][0-9]|1000)\b
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2022 02:10 AM
Hi
This is what you will have to use :
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2022 03:03 AM
Hello
I tried the solutions on the link you provided but it doesn't allow me to input 1000 and above. It only allows me to input up to 999. Also, it's not a variable. It's a field from the table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2022 03:09 AM
Hey,
Use below regular expression:
\b([0-9]|[0-9][0-9][0-9]|1000)\b
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2022 03:41 AM
Thank you
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var regexp = /^\b([0-9]|[0-9][0-9][0-9]|1000)\b/; // Reg exp to validate numbers upto 4 places /^[0-9]{1,2}$/;
if (!regexp.test(newValue) && regexp != '2000' ) //STRY0178407 > change from 100 to 2000
{
g_form.clearValue('unit_quantity');
g_form.showFieldMsg('unit_quantity', 'This field should contain only numbers - with a limit to 2000', 'error'); //change from 100 to 2000 > STRY0178407
}
}