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.

please give regular expression to validate my variable should start with 0 and only 3 digits

Rajyalakshmi
Mega Guru
 
8 REPLIES 8

Hello @Rajyalakshmi, navigate to Service Catalog > Catalog Variables > Variable Validation Regex and define following as regular expression. Then, attach the same to variable in the item

^0\d{2}$

 

Regards,

Nishant

Ankur Bawiskar
Tera Patron
Tera Patron

@Rajyalakshmi 

please use this onChange catalog client script on your variable

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    var variableName = 'your_variable_name';

    var regex = /^0\d{2}$/;
    if (!regex.test(newValue)) {
        g_form.showFieldMsg(variableName, 'Value must start with 0 and be exactly 3 digits', 'error');
        g_form.clearValue(variableName);
    } else {
        g_form.hideFieldMsg(variableName, true);
    }
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Rajyalakshmi 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Rajyalakshmi 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader