Replacing wildcard text using jquery

后端 未结 1 325
刺人心
刺人心 2021-01-20 14:45

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

1条回答
  •  面向向阳花
    2021-01-20 15:50

    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 讨论(0)
提交回复
热议问题