Regex validation on integer field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2016 10:17 AM
Hello, I'm trying add some validation to an integer field. The validation is for positive, whole numbers. I've found a regex example that works, but only for numbers 1-999.
var regExTest = /^[1-9][0-9]*$/;
g_form.hideFieldMsg("u_regex_test", true);
if(!regExTest.test(newValue)){
g_form.setValue("u_regex_test", "");
g_form.showFieldMsg("u_regex_test","Enter a valid integer", "error");
}
My understanding is that the '*' represents the number of items being validated, similar to adding {0, } for min/max numbers. I've tried this in various online regex validators and they all show that this validates correctly, but it doesn't work as anticipated. Am I missing something?
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2016 10:40 AM
Try var regExTest = /^[0-9]*$/;
Please check links in the below blog also..
Let's learn a little about Regular Expressions...
Mark correct if your issue is solved..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2016 11:12 AM
Thanks Deepa, but this does not work for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2016 11:24 AM
its working fine at my end. Can you provide screenshot .Try below on change client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return
}
var regexp = /^[0-9]*$/;
if(!regexp.test(newValue)){
alert("Please enter valid characters"); g_form.setValue('urfieldname', '');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2016 10:52 AM
Hi richcab
Here you go
if(/\D/g.test(newValue)){
g_form.setValue("u_regex_test", "");
g_form.showFieldMsg("u_regex_test","Enter a valid integer", "error");
}