Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Regex question in catalog client script

Sathiskumar_D
Giga Sage

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');
}
1 ACCEPTED SOLUTION

Muhammed Medni
Tera Guru

Hi @Sathiskumar_D 

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.

 

View solution in original post

7 REPLIES 7

Robbie
Kilo Patron
Kilo Patron

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

Muhammed Medni
Tera Guru

Hi @Sathiskumar_D 

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.

 

Thanks. Your solution worked!!

Sathiskumar_D
Giga Sage

@Robbie Thanks for your reply. But it doesn't take "n/a"