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 8 of 8
  1. #1
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,732
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts

    Question 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?

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,732
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    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.
    Last edited by Philip M; 06-20-2002 at 07:06 PM.

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,732
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    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 *.
    Last edited by Philip M; 06-20-2002 at 09:12 PM.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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. ;)

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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. ;)

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,732
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts

    Smile

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


  •  

    Posting Permissions

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