Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-20-2002, 06:52 PM   PM User | #1
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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?
Philip M is offline   Reply With Quote
Old 06-20-2002, 07:02 PM   PM User | #2
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
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
jkd is offline   Reply With Quote
Old 06-20-2002, 07:04 PM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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..
Philip M is offline   Reply With Quote
Old 06-20-2002, 07:25 PM   PM User | #4
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
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
jkd is offline   Reply With Quote
Old 06-20-2002, 09:01 PM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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..
Philip M is offline   Reply With Quote
Old 06-21-2002, 02:15 AM   PM User | #6
whammy
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
whammy is an unknown quantity at this point
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. ;)
whammy is offline   Reply With Quote
Old 06-21-2002, 02:18 AM   PM User | #7
whammy
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
whammy is an unknown quantity at this point
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. ;)
whammy is offline   Reply With Quote
Old 06-21-2002, 06:51 PM   PM User | #8
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Smile

Whammy and Dave Clark - thank you both once again for most helpful advice. You may be right - human intervention may be the solution!!
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:15 AM.


Advertisement
Log in to turn off these ads.