- 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:35 AM
Hi @Sathiskumar_D,
Try using the following regex pattern: /^\s*(\d{4}|n\/a)\s*$
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: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:59 AM
Thanks. Your solution worked!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 06:46 AM - edited 05-08-2024 06:50 AM
@Robbie Thanks for your reply. But it doesn't take "n/a"