1. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Nov 2003
    Rep Power

    Form Validation with invalid characters

    Hi guys,

    Heres a slightly tricky one for ya

    I currently have a form that im attempting to prevent users from entering ANY combination of the following characters into the fields:


    However without using several if then else statements I can only get it to validate 1 character at a time using either:

    BadChar = ".,!'$%^&*()+-=`\|/?<>@~#:;{[}]"

    If InStr(BadChar,SchoolName)>0 Then
    ConfirmPass = "Error: Invalid character"


    If InStr(SchoolName, ".") Then
    ConfirmPass = "Error: Invalid character"

    So i basically want it so any combination of the characters or the character on its own will give an error message.

    I would like to do it serverside if possible...

    Could I use an array perhaps?

    Any help appreciated thanks!
    Last edited by GregD; March 3rd, 2004 at 11:00 AM.
  2. #2
  3. Unholy Moderator
    ASP Mastermind (5000+ posts)

    Join Date
    Oct 2003
    In hell, where did you think?
    Rep Power
    Why don't you create a database or text file containing the bad characters then loop through it and compare it to what the user entered?
    do until rs.eof
       If(InStr(Request("userInput"), rs("badChars")) Then
          They have a bad character.
       End If
    Last edited by Memnoch; March 3rd, 2004 at 11:05 AM.
  4. #3
  5. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Mar 2004
    Rep Power

    Lightbulb Another Solution

    Here is another solution.

    Make a little Function and drop it in your ASP file or as an include.

    As an include you can use it where ever needed.

    PLease forgive my coding I wrote this in Notepad and did not fully test it. but the Idea behind it definately works.

    (This is short of using Javascript of course)

    Private Function Bad_Chars(chars As String)
    Dim sbadchars
    Dim icnt
    Dim sUsedBadChars
    sbadchars = ".,!'$%^&*()+-=`\|/?<>@~#:;{[}]"
    For icnt = 1 To Len(sbadchars)
    If InStr(chars, Mid(sbadchars, icnt, 1)) > 0 Then
    sUsedBadChars = sUsedBadChars & Mid(sbadchars, icnt, 1) & ","
    End If
    Bad_Chars = Left(sUsedBadChars, Len(sUsedBadChars) - 1)
    End Function

    This should return a List of all the bad characters used . It can bealtered to just returna true or false. Or a lengthy Finger pointing message pointing out the fact that the user is a bad user for using the characters.


Similar Threads

  1. Javascript Generic Form validation
    By danosullivan in forum HTML, JavaScript And CSS Help
    Replies: 2
    Last Post: February 25th, 2004, 02:34 AM
  2. form validation
    By sk01 in forum ASP Development
    Replies: 3
    Last Post: January 26th, 2004, 08:12 AM
  3. dynamic form validation
    By dizzle in forum HTML, JavaScript And CSS Help
    Replies: 4
    Last Post: January 8th, 2004, 03:24 PM
  4. javascript form validation check for first part of word
    By aliaga61 in forum HTML, JavaScript And CSS Help
    Replies: 1
    Last Post: November 8th, 2003, 11:46 PM
  5. checkbox form validation examples
    By Steve Schofield in forum .NET Development
    Replies: 1
    Last Post: August 3rd, 2000, 07:58 PM

IMN logo majestic logo threadwatch logo seochat tools logo