Web Analytics Made Easy -
StatCounter Stripping out telephone numbers - CodingForum

Announcement

Collapse
No announcement yet.

Stripping out telephone numbers

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Stripping out telephone numbers

    I have a form with a textbox and I already have a "smut engine" script which turns bad words into ******.

    What I would like to do is prevent people entering telephone numbers, and similarly turn them into *******. What I have in mind is that a phone number is recognised as being 8 consecutive digits but including blanks or hyphens.

    E.G. 1234 5678 or 1234-5678 or 012-345-6789 recognised as phone numbers.

    I don't seem to be having much success in developing a working script. Can anyone point me the right way?

    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.

  • #2
    What exactly do you want to do?

    Mask phone numbers with *, or validate them?

    I've written a few regular expressions that do the job nicely on request... but I need to know exacty what you want.
    jasonkarldavis.com

    Comment


    • #3
      Thanks jkd. I want to mask the phone numbers, that is replace them with asterisks. I do not want to validate them, but I am assuming that any string of eight or more consecutive digits (plus blanks and hyphens if any) entered into the text box is a phone number, and thus to be masked.
      Philip M
      New to the CF scene
      Last edited by Philip M; Jun 20, 2002, 03:06 PM.

      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.

      Comment


      • #4
        Well, this masks all input:

        <input type="text" onkeyup="this.value = this.value.replace(/[^\*]/g,'*')"/>

        But I'd assume you'd like somewhere to store their real phone number?

        This *sort* of works:

        <input type="text" onkeyup="if (typeof this.realValue == 'undefined') this.realValue = ''; this.realValue += this.value.charAt(this.realValue.length); this.value = this.value.replace(/[^\*]/g, '*')"/>

        But if you type too fast, realValue will contain some * oddly enough - it seems some of the code inside the event is happening asynchronously.
        jasonkarldavis.com

        Comment


        • #5
          Thanks once again jkd.

          But I don't want to mask all numeric input - just strings of numbers which are or might be telephone numbers. That is, 8 or more consecutive digits.

          To spell it out, I do not want people to be able to post things like

          "Earn lots of money with my MLM scheme - telephone 1234-5678".

          but (for example) things like "Price $1234.56" or "serial number 987654" are OK.

          I do not want to store their real phone number.

          Hope I have clarified the objective!

          By the way, only spaces and hyphens in the numeric string should be counted. This is because something like "1984/85/86/87" is OK. I realise that my idea will block the dates "1985-1986" for example, but this is not a serious problem in the context.

          So to recap: 1995/96/97/98 is OK
          $1,234,567,891 is OK
          1234-5678 or 123-4567-8912 are not and to be masked out with *.
          Philip M
          New to the CF scene
          Last edited by Philip M; Jun 20, 2002, 05:12 PM.

          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.

          Comment


          • #6
            Actually this regexp that jkd and I worked on () might help:

            <script type="text/javascript">
            <!--
            var vphone = /^\D*([1-9]\d{2})\D*(\d{3})\D*(\d{4})\D*$/
            function formatphone(x){
            if(vphone.test(x.value)){
            x.value=x.value.replace(vphone,'($1) $2-$3');
            }
            else {
            alert('Please enter a valid phone number!');
            }
            }
            // -->
            </script>

            That will match anything that contains a format of

            (anything) NNN (anything) NNN (anything) NNNN (anything)

            Other than something like that, I think it would take human intervention!
            Former ASP Forum Moderator - I'm back!

            If you can teach yourself how to learn, you can learn anything. ;)

            Comment


            • #7
              P.S. If it matches, you can use the above code to replace any numbers with * - but anyone who is savvy will figure that out, and figure out a way around it. You can only do so much... I think that in this case you might want to hire a kid to do this for cheap.
              Former ASP Forum Moderator - I'm back!

              If you can teach yourself how to learn, you can learn anything. ;)

              Comment


              • #8
                Whammy and Dave Clark - thank you both once again for most helpful advice. You may be right - human intervention may be the solution!!

                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.

                Comment

                Working...
                X