Response.Form

1. Junior Member
Join Date
Dec 1969
Posts
2

## Response.Form

How can you check a response.form to make sure there are no numbers in it? I tried the IsNumeric function but that doesn&#039;t seem to work

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Yeah, isNumeric not good enough...

For example, "xy27ab" will *not* be numeric, but it still has two digits in it.<BR><BR>The only way to do this is to test it one character at a time:<BR><BR>&#060;%<BR>val = Request("xxx")<BR>For i = 1 To Len(val) &#039; look at all characters<BR> ch = Mid(val,i,1) &#039; get one character<BR> If ch &#062;= "0" AND ch &#060;= "9" Then<BR> Response.Write "Found digit " & ch & "&#060;BR/&#062;"<BR> End If<BR>Next<BR>%&#062;<BR><BR>Adapt that code as needed to your own purposes.<BR><BR>Probably best to make it a function:<BR><BR>&#060;%<BR>Function CheckVal( val )<BR> For i = 1 To Len(val) &#039; look at all characters<BR> ch = Mid(val,i,1) &#039; get one character<BR> If ch &#062;= "0" AND ch &#060;= "9" Then<BR> CheckVal = False<BR> Exit Function<BR> End If<BR> Next<BR> CheckVal = True<BR>End Function<BR>%&#062;<BR><BR>And then use it thus:<BR><BR>&#060;%<BR>whatsit = Request("whosit")<BR>If CheckVal(whatsit) = False Then<BR> Response.Write "whosit form field is invalid"<BR>End IF<BR>%&#062;<BR>

3. Junior Member
Join Date
Dec 1969
Posts
2

## RE: Yeah, isNumeric not good enough...

I tried that and it didn&#039;t exactly work. If I can avoid using functions I would prefer that as I am not familiar with them. Also the coding has to check for invalid characters such as "&" and "#". This is only part of the whole program but I have isolated it so that I can ensure this will work...<BR>&#060;%Option Explicit%&#062;<BR>&#060;html&#062;<BR>&#060;body& #062;<BR>&#060;form method ="post" action="test2.asp"&#062;<BR>Please enter your first name<BR>&#060;input type="text" name="fname"&#062;<BR>&#060;input type="submit" name="click" value="enter"&#062;<BR>&#060;%<BR>Dim i, word, thechar, msg<BR>If request.form("click")="enter" then<BR> word = request.form("fname")<BR><BR> For i = 1 to Len(word)<BR> thechar = Mid(word,i,1)<BR> If theChar &#062;= "0" AND theChar &#060;= "9" Then <BR><BR> msg = "Please check your format"<BR> Else <BR> msg = "The word is " & word & "."<BR> End If<BR> Next<BR>End If<BR><BR>If msg &#060;&#062; "" then<BR> response.write "" & msg & ""<BR>End If<BR><BR>%&#062; <BR>&#060;/form&#062;<BR>&#060;/body&#062;<BR>&#060;/html&#062;<BR><BR>It looks right but it still doesn&#039;t work!

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Of COURSE it doesn't work!

For i = 1 to Len(word)<BR> thechar = Mid(word,i,1)<BR> If theChar &#062;= "0" AND theChar &#060;= "9" Then <BR> msg = "Please check your format"<BR> Else <BR> msg = "The word is " & word & "."<BR> End If<BR>Next<BR><BR>Let&#039;s use the string "7A" to test that code.<BR><BR>First time through, theChar variable gets the character "7". A digit. So you set the msg variable to<BR> "Please check your format"<BR>Second time through, theChar variable gets the character "A". Not a digit. So you set the msg variable to<BR> "The word is " & word & "."<BR>In the process WIPING OUT the error message from the first character!<BR><BR>THAT IS WHAT EXIT FOR was invented for.<BR><BR><BR><BR>&#039; assume the word is okay<BR>msg = "The word is " & word & "."<BR>For i = 1 to Len(word)<BR> thechar = Mid(word,i,1)<BR> If theChar &#062;= "0" AND theChar &#060;= "9" Then <BR> msg = "Please check your format"<BR> Exit For<BR> End If<BR>Next<BR><BR>If you had used my function, it would have worked.<BR><BR>*********************************** **<BR><BR>You never *said* you wanted to eliminate OTHER characters. You *ONLY* mentioned digits.<BR><BR>SO WHAT IS IT YOU REALLY WANT? <BR><BR>Do you want *ONLY* letters? Do you allow both upper and lower case? Do you allow *some* non-letters (such as space, perhaps)?<BR><BR>If you don&#039;t tell us the EXACT QUESTION then we can&#039;t give you and exact answer.<BR><BR><BR><BR>

#### Posting Permissions

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