Ankur Bawiskar
Tera Patron

@vahini 

try this

function onChange(control, oldValue, newValue, isLoading) {
    if (newValue != '') {
        var regex = /^https:\/\/theabc\.sharepoint\.com\/sites\/[A-Za-z0-9_-]+$/;
        if (!regex.test(newValue)) {
            g_form.clearValue('provide_the_custom_url');
            g_form.showFieldMsg('provide_the_custom_url', "Please follow the URL format in the help text. Enter the URL you want into the 'YourURL' space. Only hyphens and underscores are allowed.", "error");
        }
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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