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 7 of 7
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,466
    Thanks
    15
    Thanked 0 Times in 0 Posts

    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 

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,118
    Thanks
    80
    Thanked 4,555 Times in 4,519 Posts
    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.

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,466
    Thanks
    15
    Thanked 0 Times in 0 Posts
    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)

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,118
    Thanks
    80
    Thanked 4,555 Times in 4,519 Posts
    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, "" )
    Last edited by Old Pedant; 03-01-2013 at 07:50 PM.
    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.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,118
    Thanks
    80
    Thanked 4,555 Times in 4,519 Posts
    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.
    Last edited by Old Pedant; 03-01-2013 at 07:51 PM.
    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.

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,118
    Thanks
    80
    Thanked 4,555 Times in 4,519 Posts
    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.


  •  

    Posting Permissions

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