View Full Version : Database entry valid?

01-13-2005, 07:29 AM
Is there a way or a function that I could use to check a user's entry before submitting it to the database? i mean is there a way that I can scan the user's entry for all characters that would be illegal for database storage?

And i don't mean like simple form validation where you check to see that the user entered text and not numbers for example.

I mean like a big text area that you plan to store as a memo field. How can you know that the entry willl be valid?

01-13-2005, 04:45 PM
you can see if they have entered only valid characters by using InStr and Asc(i) in a loop.. something like this

strTextToBeChecked = "hello $ how are you today jy13?"

blnIllegalChars = False
For i = Chr(A) to Chr(Z)
If InStr(UCase(strTextToBeChecked), Asc(i)) Then blnIllegalChars = True

If blnIllegalChars = True Then
Response.Write "illegal chars entered!"
Response.Write strTextToBeChecked
End Ifthis checks letters only, you could change this to include numbers or whatever, i just cant remember which numbers should be included, you could also check this against lowercase characters or whatever

01-13-2005, 05:05 PM
It gives me this error: :confused:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: ""]'
/thegroupgenesis/tests/testing2.asp, line 8

Oh and please remember that the database will permit the use of characters that fall outside of the A - Z range as in some characters are allowed in the database.... but others are not. :)

What I wanna find out is filtering out those are not :thumbsup:

01-14-2005, 09:51 AM
yea, i didnt test it and i said you should change it to include the right characters.. its probably an error on Chr(A) should be Chr("A")

i cant test from college :p

my point was its probably smaller to loop through these than loop through the string, using instr instead of looping with mid etc which is what a lot of people do.. im just showing a not too unefficient way of doing it, as it only has a max of 255 itterations, you could probably do a - 9 or something liek that, and then to ^ or whatever like that in a separate loop, just grouping them together as you can, i cant say wht to use 'cos i dont know the numbers and i dont know what characters you want to be illegal :p

01-14-2005, 01:12 PM
thanks for your help thus far.... :thumbsup: :thumbsup: :thumbsup: but this really has nothing to do with what characters I want to be illegal, rather it has Everything to do with the characters that are illegal in MS Access.

The problem has been plaguing me...... I write some text, copy one or two symbols... and then my page doesn't load and I get a nasty access error instead....

So I know that there are characters that are illegal... i want users to be able to use all the symbols that are legal.... but prompt them when they are using symbols that aren't legal