开发者

Capturing number from HTML text

I want to capture phone numbers from an HTML document. I have used a pattern but its also selecting numbers that are the part of attributes of tags.

var m开发者_StackOverflow中文版yArray = $('body').html().match(/([\s()-.])*(0[1-9]|[+][1-9]|[+][+][1-9]|00[1-9])(([\s()-.\/])*[0-9]+)*/g);


The html() method in jQuery uses the innerHTML JavaScript property. The innerHTML property retrieves the source of an element at runtime. If you need the pure text content of an element (without HTML tags), use the innerText and textContent properties.

Example:

var bodyText = (document.body.textContent === undefined) ? document.body.innerText : document.body.textContent;
var myArray = bodyText().match (/([\s()-.])*(0[1-9]|[+][1-9]|[+][+][1-9]|00[1-9])(([\s()-.\/])*[0-9]+)*/g);

For further details and examples:innerText property, textContent property, innerHTML property.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜