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

Amarjeet Pal
Kilo Sage
Kilo Sage

Hello Rushi Bhosale,

Could you please try onChange client script with regex and let me know if you need any help in scripting.

Thanks,

Amarjeet Pal
Please HIT Helpful if you find my article helpful.

ersureshbe
Giga Sage
Giga Sage

Hi, can you check the existing variable type and check associated script in that field. If field type is string it will allow else its a problem to enter the special characters and white spaces.

Regards,
Suresh.

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

Community Alums
Not applicable

Thank @Amarjeet Pal for providing me a script. Now its working properly 

 

Regards

Rushikesh