Remove Alphabets, special characters and spaces in a field

pruthvi9
Kilo Contributor

Hi Experts,

How can i remove/trim the alphabets, spaces and special characters from field value where i need only numerical

example : contract = acfg34 54@#$674 cbf345@

the result i want is 3454674345

i tried with var res = str.replace(/[^a-zA-Z0-9]+/g, ""); but it is working for special characters only.

 

Thanks in Advance

1 ACCEPTED SOLUTION

P-Rudenko-SN
ServiceNow Employee
ServiceNow Employee

Use the string's .replace method with a regex of \D, which is a shorthand character class that matches all non-digits:

myString = myString.replace(/\D/g,'');

View solution in original post

2 REPLIES 2

P-Rudenko-SN
ServiceNow Employee
ServiceNow Employee

Use the string's .replace method with a regex of \D, which is a shorthand character class that matches all non-digits:

myString = myString.replace(/\D/g,'');

Thank you it is working