Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Filed Validation for alphanumeric

Prudhvi Raj4
Tera Guru

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

 

1 ACCEPTED SOLUTION

Murthy Ch
Giga Sage

Hi @Prudhvi Raj4 

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:

MurthyCh_0-1670223417673.png

MurthyCh_1-1670223438625.png

Hope it helps.

 

 

 

Thanks,
Murthy

View solution in original post

2 REPLIES 2

Murthy Ch
Giga Sage

Hi @Prudhvi Raj4 

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:

MurthyCh_0-1670223417673.png

MurthyCh_1-1670223438625.png

Hope it helps.

 

 

 

Thanks,
Murthy

jaheerhattiwale
Mega Sage

@Prudhvi Raj4  You can use following code to check the - after 4 letters

 

if(newValue[4] != "-"){
    //Error message here
}else if(newValue[9] != "-"){
    //Error message here
}else if(newValue[14] != "-"){
    //Error message here
}else if(newValue[19] != "-"){
    //Error message here
}
 
Please mark as correct answer if this solves your issue

 

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023