Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Not sure how to tweak this code

    Hello, so I downloaded a firefox add-in from the VOIP hosting provider for my company. The function is it detects phone numbers in the browser and makes them clickable. Unfortunately this line of code makes it read numbers as (512)123-1234. What we need it to do is read numbers as one solid block of 10 digits, like 5121231234. I have tried some changes to no avail. I believe this line of code that I paste below is responsible for determining what is read from a webpage with it currently only detecting numbers like (512)123-1234. Does someone know what this line of code needs to say, or am I looking in the wrong spot? Thanks!

    var phone_number_regex_us = /(?:[^\&\*\=\/\\\%\#\$\w\+\-\.\,]|^)\s*(?:\+\s*1|1)?\s*[\(\-\.]?\s*(?:8[05678]{1}[0-9]{1}\s*[\)\-\.]?\s*[0-9a-zA-Z]{3}\s*[\-\.]?\s*[0-9a-zA-Z]{4}|[2-9]{1}[0-9]{2}\s*[\)\-\.]?\s*[0-9]{3}\s*[\-\.]?\s*[0-9]{4})/;

  • #2
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I should clarify, when I say it reads numbers, I mean it detects patterns on the website. We need it to detect blocks of 10 numbers, and not numbers with xxx-xxx-xxx. Thanks

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Try

    Code:
    var phone_number_regex_us = /\d{10}/

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,193
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    And you could also do it more flexibly. For example:
    Code:
    var phone_number_regex_us = /(\d{10}|\(\d{3}\)\s?\d{3}\-\d{4})/;
    which would accept either 8005551212 or (800) 555-1212.

    Or you could make it still more flexible. Up to you.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •