开发者

Replacing wildcard text using jquery

I have a database that contains company information (address, telephone etc)

On some of the telephone numbers it will have an international code: +44 (0) 123 12345

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

I need to strip the (0)

I have the follo开发者_高级运维wing code:

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

which works on (0) - but how do I do this for wildcards


Use a regular expression.

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

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

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

Live example here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜