kessa
06-18-2006, 06:23 PM
Hi All,
I've got the following bit of code which I use to ensure a name doesn't contain a number or an @ symbol:
strName = Request.Form("name")
strName = LCase(strName) ' Add if you want your tests to be case-insensitive!
If InStr(strName, "n/a") > 0 OR InStr(strName, "@") > 0 OR InStr(strName, "1") > 0 OR InStr(strName, "2") > 0 OR InStr(strName, "3") > 0 OR InStr(strName, "4") > 0 OR InStr(strName, "5") > 0 OR InStr(strName, "6") > 0 OR InStr(strName, "7") > 0 OR InStr(strName, "8") > 0 OR InStr(strName, "9") > 0 OR InStr(strName, "0") > 0 Then
update_fail=1
End If
At the moment it works fine, but I was just curious to know if there may be a more streamlined way of doing this (perhaps some kind of loop?) - my main concern is that I use the same method in other form fields (to help detect spam in form comments, etc) and some of these are now getting quite long (20 or so words to look out for), so I seems a bit of waste to keep repeating "OR InStr(strName, "whatever") > 0" if there is a way I could perhaps just declare the words on their own, and then loop through them.
Also, on a seperate issue, I also wondered if it was possible to ensure that the user has entered at least "X" number of characters into a form field (this isn't related to the issue above and so would need to be a seperate function)
For example - if they have entered something into the "telephone" field, then I want to make sure that it is at least 5 characters, etc
Thanks
Kessa
I've got the following bit of code which I use to ensure a name doesn't contain a number or an @ symbol:
strName = Request.Form("name")
strName = LCase(strName) ' Add if you want your tests to be case-insensitive!
If InStr(strName, "n/a") > 0 OR InStr(strName, "@") > 0 OR InStr(strName, "1") > 0 OR InStr(strName, "2") > 0 OR InStr(strName, "3") > 0 OR InStr(strName, "4") > 0 OR InStr(strName, "5") > 0 OR InStr(strName, "6") > 0 OR InStr(strName, "7") > 0 OR InStr(strName, "8") > 0 OR InStr(strName, "9") > 0 OR InStr(strName, "0") > 0 Then
update_fail=1
End If
At the moment it works fine, but I was just curious to know if there may be a more streamlined way of doing this (perhaps some kind of loop?) - my main concern is that I use the same method in other form fields (to help detect spam in form comments, etc) and some of these are now getting quite long (20 or so words to look out for), so I seems a bit of waste to keep repeating "OR InStr(strName, "whatever") > 0" if there is a way I could perhaps just declare the words on their own, and then loop through them.
Also, on a seperate issue, I also wondered if it was possible to ensure that the user has entered at least "X" number of characters into a form field (this isn't related to the issue above and so would need to be a seperate function)
For example - if they have entered something into the "telephone" field, then I want to make sure that it is at least 5 characters, etc
Thanks
Kessa