We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

In single line text catalog variable Validation with URL

Raj115
Tera Contributor

Dear all ,

I have one variable  (Type - single line text) and I need a Regex Pattern that allows users that URL should not contain more than 500 words.

I written a on change client script

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

//Type appropriate comment here, and begin script below


function validateURL(text) {

var urlRegex = /(https?:\/\/[^\s]+)/g;


var urls = text.match(urlRegex);

if (urls) {

for (var i = 0; i < urls.length; i++) {
var url = urls[i];

var urlWithoutProtocol = url.replace(/(^\w+:|^)\/\//, '');
var words = urlWithoutProtocol.split(/\s+/).length;
if (words > 500) {
return false; // URL contains more than 500 words
}
}
}

return true; // URL is valid
}

}

 

IT is not working , could you help me in this.

Regards,

 

 

 

0 REPLIES 0