- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 06:17 AM
Hello,
I've a question on regex. There is a variable which should accept 4 digit number or 'N/A' (not applicable). I tried regex in catalog client script, But it isn't working.
Code snippet from onChange CS
var regex1=/^[nN]{1}\/[aA]{1}$ | ^\d{4}$/;
if (!regex1.test(newValue)) {
g_form.clearValue('grade_series');
g_form.showFieldMsg('grade_series', 'Series is a 4-digit E.g., 0123 or 1234 or N/A', 'error');
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 06:44 AM
Try using the following regex:
var regex1 = /^(N\/A|\d{4})$/i;
if (!regex1.test(newValue)) {
g_form.clearValue('grade_series');
g_form.showFieldMsg('grade_series', 'Series should be a 4-digit number or N/A', 'error');
}
Thanks and Regards
Medni
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 06:50 AM - edited 05-08-2024 06:52 AM
Hi @Sathiskumar_D,
I did test this before responding, let me try again on my PDI to make sure. Give me 5 mins
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 07:06 AM - edited 05-08-2024 07:07 AM
Hi @Sathiskumar_D,
Tried and tested on my PDI - Regex syntax: /^\s*(\d{4}|n\/a)\s*$/i
Full code snippet:
var regex1 = /^\s*(\d{4}|n\/a)\s*$/i;
if (!regex1.test(newValue)) {
g_form.clearValue('grade_series');
g_form.showFieldMsg('grade_series', 'Series is a 4-digit E.g., 0123 or 1234 or N/A', 'error');
}
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 06:51 AM
Hi @Sathiskumar_D ,
Could you please try the below , i just checked in pdi its working,
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var regex1 = /\b(?:\d{4}|N\/A)\b/;
if (!regex1.test(newValue)) {
g_form.clearValue('grade_series');
g_form.showFieldMsg('grade_series', 'Series is a 4-digit E.g., 0123 or 1234 or N/A','error');
}
}
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang