Go Back   CodingForums.com > :: Server side development > ASP

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 02-28-2013, 06:33 PM   PM User | #1
esthera
Senior Coder

 
Join Date: May 2004
Posts: 1,431
Thanks: 14
Thanked 0 Times in 0 Posts
esthera can only hope to improve
not allowing phone numbers

I have a variable that is submitted by a text box and I don't want them to be able to enter in phone numbers

my code is below but the problem is users are getting around by entering it

7 1 8 2 2 2 2 2 2 2 within the text


How can I get around this?

PHP Code:
Function checkphone(sText)
   
checkphone=""
    
Dim arrWordsxcurWord
    Dim sEmail
sNamesDomain
    Dim dotIndex
y
    
    
'remove any extra spaces
    sText = Trim(sText)
    Do Until InStr(sText, "  ")<1
        sText = Replace(sText, "  ", " ")
    Loop
    
    '
split into words
    arrWords 
Split(sText" ")
    
    
'look for email, initialize return value
    sEmail = ""
    For x=0 To UBound(arrWords)
        curWord = arrWords(x)
         icurword=curword
        curword=replace(curword,"(","")
        curword=replace(curword,")","")
        curword=replace(curword,"-","")
    '    
response.Write curword "<br>"
        
if isnumeric(curwordthen 
           
' response.Write curwords & " is numeric<br>"
            if len(curword)>=9 then 
         '   
response.Write "<hr>" curword " is a problem<hr>"
            
checkphone=icurword
            end 
if    
        
end if
    
Next
    
    
'free allocated memory
    Erase arrWords

    

    '
if checkphone="" then checkphone=stext

checkphone 
=  DeleteThisPattern(checkphone,"\d{10}")    
    
    
End Function 
esthera is offline   Reply With Quote
Old 02-28-2013, 10:26 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Maybe if you told us what you *WANT* the users to enter it would be easier?

If you simply want to reject any entry that has *ONLY* (say) digits and spaces, then that's easy:
Code:
Function rejectStuff( txt )
    Set re = New RegExp
    re.Pattern = "[^\d\s]"
    rejectStuff = re.Test( txt )
End Function

If rejectStuff( Request("someFormField") ) Then
    ... idiot user ...
Else
   ... maybe okay? ...
End If
But that would still allow something like "123-456-7890" because the "-" character is neither a digit nor a space.

It's much better to say what you are *expecting* (e.g., an email address??) than what you want to reject.
__________________
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.
Old Pedant is offline   Reply With Quote
Old 03-01-2013, 05:22 AM   PM User | #3
esthera
Senior Coder

 
Join Date: May 2004
Posts: 1,431
Thanks: 14
Thanked 0 Times in 0 Posts
esthera can only hope to improve
no the users enter in full details but i'm trying to get rid of any numbers
(they are not allowed to post their phone number)
esthera is offline   Reply With Quote
Old 03-01-2013, 06:45 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
But suppose the user enters "The gross national product of England averages 2,378,111,228 pounds per day."

???

That is a 10 digit number that looks like a phone number. What would you have the system do with it?

Or what would you do about "My phone number is eight zero zero five five five one two one two." ???

Anyway, if you simply want to reject all digits, I gave you the answer in the first post, excepting that you should remove the \s in there.

If you want to zap all digits, just use
Code:
    Set re = New RegExp
    re.Pattern = "\d"
    re.Global = True
    txt = re.Replace( txt, "" )
__________________
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.

Last edited by Old Pedant; 03-01-2013 at 06:50 PM..
Old Pedant is offline   Reply With Quote
Old 03-01-2013, 06:48 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Since it's unlikely that anybody would enter a 10 digit number *except* for a phone number, maybe you could do this:
Code:
txt = "I want 30 pounds of butter and 12 pounds of flour."

Set re = New RegExp
re.Pattern = "[^\d]"
re.Global = True
If Len( re.Replace( txt, "" ) ) > 6 Then
    ... reject message ... has 7 or more digits in it ...
Else
    ... has 6 or few digits, so not a phone # ... it is okay ...
End If
You can decide whether to use 6 or 9 or whatever as your cutoff point.
__________________
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.

Last edited by Old Pedant; 03-01-2013 at 06:51 PM..
Old Pedant is offline   Reply With Quote
Old 03-01-2013, 09:30 PM   PM User | #6
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,451
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
What about the phone number "eatatjohns" (which when entered into a phone will dial 3282856467)? Phone numbers don't have to be entered as numbers.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 03-01-2013, 10:36 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
LOL! And I thought "eight zero zero..." was a nice workaround.
__________________
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.
Old Pedant 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 06:24 PM.


Advertisement
Log in to turn off these ads.