How to include a Phone mask on a Catalog Variable on Service Portal

marcelo_moreli
Mega Guru

I have a variable "Phone" with a mask like "(000) 00000-0000".

It works perfectly on the Fulfiller screen, but now that we are migrating to Service Portal, I've noticed that you cannot use jQuery or DOM on Client Scripts.

Is it possible to put a phone mask on a variable so that it works on the Service Portal?

Thanks,

1 ACCEPTED SOLUTION

marcelo_moreli
Mega Guru

Answering my own question from 2y ago: In order to use jQuery from client scripts on the service portal, you should use this.$ instead of $

 

View solution in original post

7 REPLIES 7

Jan Strama
Mega Contributor

Hi, I habe the same issue too, any help is highly appriciated.

Thanks!

Jan Strama
Mega Contributor

Hi Guys,

 

I have sorted this out now with the a onSubmit Client script (see below).

I am using international number formating and a "-" to seperate the last digits. This is based on the example from here:

https://community.servicenow.com/community?id=community_question&sys_id=3a701f29dbdcdbc01dcaf3231f96...

Hope this helps you.

 

function onSubmit() {
	  g_form.hideAllFieldMsgs('error');
	  var displayError = 0;
	//declare Variables and populate with Values from the Fields
	var phone = g_form.getValue('u_phone');
	var mobile = g_form.getValue('u_mobile');
	var facsimile = g_form.getValue('u_telefax');
	var cancleSubmit = false;
	//console.log(phone + ' ' + mobile + ' ' + facsimile);
	
	//Check Numbers are correctly entered in the required Mask before checking if the number is taken:
		
			//Check Phone Format Mask +##_(2-4 #)_(3-6#)(-)(1-4#)
			   var phone_pattern = /^\+(\d{1,3})[\s](\d{2,4})[\s](\d{3,6})[-](\d{1,4})$/;
				  if(!phone_pattern.test(phone)){
					  g_form.showFieldMsg('u_phone', 'Phone Number Format does not match requirements - example for valid format +49 201 240588-0', 'error');
				  displayError = 1;
				  }
	//Check Mobile Phone Mask
	if(mobile != ''){
				var mobile_pattern = /^\+(\d{1,3})[-|\s](\d{3,4})[-|\s](\d{3,12})$/;
				if(!mobile_pattern.test(mobile)){
					g_form.showFieldMsg('u_mobile', 'Mobile Phone Number Format does not match requirements example for valid format +49 150 12345678', 'error');
				displayError = 1;
				
				}
	}
		
	//Check Facsimile Mask
	if(facsimile != ''){
				var facsimile_pattern = /^\+(\d{1,3})[\s](\d{2,4})[\s](\d{3,6})[-](\d{1,4})$/;
				if(!facsimile_pattern.test(facsimile)){
					g_form.showFieldMsg('u_telefax', 'Telefax Number Format does not match requirements - example for valid format +49 201 240588-0', 'error');
				displayError = 1;
				
				}
	}
if(displayError == 1){
	return false;
	
}
console.log('DEBUG:script ended');	
}

marcelo_moreli
Mega Guru

Answering my own question from 2y ago: In order to use jQuery from client scripts on the service portal, you should use this.$ instead of $