- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2020 09:19 AM
Hi All,
I have requirement to validate the number entered in a field . For this I created Onchange client script and below RegEx is not working .It is not accepting the number even I give in below format .
Please guide.
Number format should be - 123-45-6789
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var pattern = /^([0-9]{3})+([-]{1})+((0-9)]{2})+([-]{1})+([0-9]{4})$/;
if (!pattern.test(newValue)) {
g_form.clearValue('u_social_security_usa');
g_form.showFieldMsg('u_social_security_usa', 'Enter a valid SSN ', 'error', true);
}
//Type appropriate comment here, and begin script below
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2020 09:40 AM
Hi
Your RegEx isn't doing quite what you're expecting it to.
Try with this:
/^\d{3}-\d{2}-\d{4}$/
Cheers
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2020 09:40 AM
Hi
Your RegEx isn't doing quite what you're expecting it to.
Try with this:
/^\d{3}-\d{2}-\d{4}$/
Cheers
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2020 11:35 AM
Thanks
Could you please let me what was the mistake in my original RegEx .
Does \d indicate a digit ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2020 01:02 PM
Hi
Yes, \d means digit.
If you want a good visual reputation of what your regex is doing, you can paste it into https://regexr.com/ and it'll tell you down at the bottom what it's trying to validate against.