Replacing wildcard with jquery

I have a database containing company information (address, phone, etc.)

For some phone numbers, he will have an international code: +44 (0) 123 12345

where (0) will be different numbers depending on the country.

I need to take off (0)

I have the following code:

var el = $('#contactdetails');
el.html(el.html().replace("(0)", "-"));

which works on (0) - but how to do it for wildcards

+3
source share
1 answer

Use regex.

var el = $('#contactdetails');
el.html(el.html().replace(/\([0-9]\)/, "-"));

If there is more than one digit, use *for any number of occurrences of the previous expression.

el.html(el.html().replace(/\([0-9]*\)/, "-"));

Live example is shown here.

+5
source

Source: https://habr.com/ru/post/1783680/


All Articles