Regex - To only have numbers and special symbols in a fields

erpradeep
Kilo Contributor

Hi All,

I have to write a regular expression to allow only numbers and special symbols in a catalog item field.

1 ACCEPTED SOLUTION
4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

something like this

^(?=.*?[1-9])[0-9()-]+$

Regards
Ankur

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

Hi,

sample script

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

	var regex = /^(?=.*?[1-9])[0-9()-]+$/;

	if(!regexp.test(newValue))
	{
		alert('Only numbers and special characters are allowed');
		g_form.clearValue('variable');
	}

	//Type appropriate comment here, and begin script below

}

Regards
Ankur

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

@erpradeep 

Hope you are doing good.

Did my reply answer your question?

If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

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

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi - You can define regular expression at variable level. Details below.

https://docs.servicenow.com/bundle/orlando-it-service-management/page/product/service-catalog-manage...