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 arrWords, x, curWord
Dim sEmail, sName, sDomain
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(curword) then
' 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
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.
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..