Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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

@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  ||  10x 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  ||  10x 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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader