Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Phone Number field does not allow Space and special characters in Catalog item

Community Alums
Not applicable

Hi Team

I am facing a issue in Phone number field type

I want to display an Error message when the Phone number field allows special characters and spaces.

 

regards

Rushikesh

1 ACCEPTED SOLUTION

Amarjeet Pal
Kilo Sage
Kilo Sage

Hello @Community Alums 

Could you please try below script and check if this works for you 

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

var regex = /^[0-9]+$/; // Regular expression to allow only numbers

if (!regex.test(newValue)) {
g_form.showErrorBox('phone_number', 'Phone number should only contain numbers');
}
}
Thanks,

Amarjeet Pal

View solution in original post

5 REPLIES 5

Community Alums
Not applicable

Hello @Community Alums,

Please refer to this : https://www.servicenow.com/community/spm-forum/how-can-i-restrict-spaces-and-special-characters-in-a-string/m-p/976894

 

@Community Alums, Please mark my answer as "Accept as Solution" and "Helpfuls." If it works for you.

 

Thank you!