0

While developing chrome extension for detecting the mobile numbers, I have used javascript included in to the content script. For implementation I used this link for detection but using this javascript are also detecting from html attributes like

<a href="1234567890.pdf"> file 1 </a>

Since, 1234566780 is not a mobile numbers it get detected as a number. How can these html tags can be ignored while performing this replacing task. Is there any javascript function to ignore the HTML tags ?

I think this can be done by implementing the regex of

1. ignoring the characters start with "<" and end with ">" 

here is html file,

<html>

    <head>
        <title>test</title>
        <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript">

        </script>
        <script>
            $(document).ready(function () {
                $('body').each(function () {
                    $(this).html($(this).html().replace(/(\d\d\d\d\d\d\d\d\d\d)/g, '<a href="#">$1</a>'));
                });
            });
        </script>
    </head>

    <body>Vignesh - 9427415949 <a href="1234567890.pdf"> file 1 </a>

    </body>

</html>
Community
  • 1
  • 1
Vignesh Prajapati
  • 2,320
  • 3
  • 28
  • 38
  • Without seeing the code of the replacing task we can only guess. My guess is that you need to amend the jQuery selector to be more specific – gvee Aug 29 '13 at 11:30
  • 4
    One of the most frequently asked questions. A good answer is here : http://stackoverflow.com/questions/8503121/replace-words-in-a-string-but-ignore-html – The Dark Knight Aug 29 '13 at 11:35
  • 1
    Point blank replacing the html of the element is bad. It removes event handlers and other things you might want to keep. – SeinopSys Aug 29 '13 at 11:38
  • You may additionally check for spaces before and after the 10 digits. Also, if you're looking for areas specific numbers, it is a good option to check for numbers starting with a subset of the 10 digits. – Rohan Sood Aug 30 '13 at 09:33

0 Answers0