- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2022 10:13 PM
Hello,
We have a requirement to validate the catalog variable to check it should have the alphanumeric of 24 characters with hyphen after every 4 digits, I have written the code to check the alphanumeric of 24 characters with hyphen but not able check that hyphen should be after every 4 digits (Ex: ADCB-1234-AD23-ASER-12AD).
Please let me know if there is a way to validate the above scenario.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('claimed_redemption_code');
var patt = new RegExp("^[a-zA-Z0-9_-]*$");
if (!patt.test(newValue + '') || newValue.length != "24")
g_form.showFieldMsg('claimed_redemption_code', 'Invalid Code', 'error');
}
Thanks,
Prudhvi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2022 10:57 PM
You can do this using Client script but instead of that you can create a record in Variable Validation Regex and use in it variable configuration.
^([0-9A-Z]{4}[-]){4}([0-9A-Z]){4}?$
See screenshot below for your reference:
Hope it helps.
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2022 10:57 PM
You can do this using Client script but instead of that you can create a record in Variable Validation Regex and use in it variable configuration.
^([0-9A-Z]{4}[-]){4}([0-9A-Z]){4}?$
See screenshot below for your reference:
Hope it helps.
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2022 11:57 PM
@Prudhvi Raj4 You can use following code to check the - after 4 letters
ServiceNow Community Rising Star, Class of 2023