473,837 Members | 1,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to check user input for illegal characters?

Is there a way to check user input for illegal characters?

For example, a user enters something into a text box and clicks OK.
At that point I'd like to run code such as this:

illegal = Array(\, /, :, *, ?, ", <, >, |)

If Me.TextBox Contains illegal Then
MsgBox "You entered illegal characters. Please try again."
Me.TextBox = Null
Exit Sub
End If

Any suggestions welcome!

Thanks!
Nov 12 '05 #1
14 42442
PMB
I'm not sure this is an answer, but if you use the ASCII character maps for
legal letters and numbers that would be a way to do this.

I can't help you anymore than that.

Michael
"deko" <dj****@hotmail .com> wrote in message
news:Lc******** *********@newss vr27.news.prodi gy.com...
Is there a way to check user input for illegal characters?

For example, a user enters something into a text box and clicks OK.
At that point I'd like to run code such as this:

illegal = Array(\, /, :, *, ?, ", <, >, |)

If Me.TextBox Contains illegal Then
MsgBox "You entered illegal characters. Please try again."
Me.TextBox = Null
Exit Sub
End If

Any suggestions welcome!

Thanks!

Nov 12 '05 #2
I suppose I cd put the illegal ascii codes in an array, but how to grep for
them in a string?
"PMB" <pm*****@megavi sion.com> wrote in message
news:mF******** ********@news.u swest.net...
I'm not sure this is an answer, but if you use the ASCII character maps for legal letters and numbers that would be a way to do this.

I can't help you anymore than that.

Michael
"deko" <dj****@hotmail .com> wrote in message
news:Lc******** *********@newss vr27.news.prodi gy.com...
Is there a way to check user input for illegal characters?

For example, a user enters something into a text box and clicks OK.
At that point I'd like to run code such as this:

illegal = Array(\, /, :, *, ?, ", <, >, |)

If Me.TextBox Contains illegal Then
MsgBox "You entered illegal characters. Please try again."
Me.TextBox = Null
Exit Sub
End If

Any suggestions welcome!

Thanks!


Nov 12 '05 #3
On Wed, 01 Oct 2003 22:05:31 GMT in comp.databases. ms-access, "deko"
<dj****@hotmail .com> wrote:
Is there a way to check user input for illegal characters?

For example, a user enters something into a text box and clicks OK.
At that point I'd like to run code such as this:

illegal = Array(\, /, :, *, ?, ", <, >, |)

If Me.TextBox Contains illegal Then
MsgBox "You entered illegal characters. Please try again."
Me.TextBox = Null
Exit Sub
End If

Any suggestions welcome!


what I do in my supplier shortname where I disallow special characters
to aid searching is use the KeyPress event, e.g.

(edited for brevity)
Private Sub txtShortname_Ke yPress(KeyAscii As Integer)
Dim strchar As String
Dim strNoShortName As String
strNoShortName = ",.?/\¬`!"£$%^&*-+='@#~:;|<>¦-_{}[]()`¬'"
If InStr(1, strNoShortName, strchar) Then
KeyAscii = 0
End If
End Sub
--
A)bort, R)etry, I)nfluence with large hammer.
Nov 12 '05 #4
Thanks... I'll give it a go and post back
"Trevor Best" <bouncer@localh ost> wrote in message
news:qu******** *************** *********@4ax.c om...
On Wed, 01 Oct 2003 22:05:31 GMT in comp.databases. ms-access, "deko"
<dj****@hotmail .com> wrote:
Is there a way to check user input for illegal characters?

For example, a user enters something into a text box and clicks OK.
At that point I'd like to run code such as this:

illegal = Array(\, /, :, *, ?, ", <, >, |)

If Me.TextBox Contains illegal Then
MsgBox "You entered illegal characters. Please try again."
Me.TextBox = Null
Exit Sub
End If

Any suggestions welcome!


what I do in my supplier shortname where I disallow special characters
to aid searching is use the KeyPress event, e.g.

(edited for brevity)
Private Sub txtShortname_Ke yPress(KeyAscii As Integer)
Dim strchar As String
Dim strNoShortName As String
strNoShortName = ",.?/\¬`!"£$%^&*-+='@#~:;|<>¦-_{}[]()`¬'"
If InStr(1, strNoShortName, strchar) Then
KeyAscii = 0
End If
End Sub
--
A)bort, R)etry, I)nfluence with large hammer.

Nov 12 '05 #5
"deko" <dj****@hotmail .com> wrote in message
news:Lc******** *********@newss vr27.news.prodi gy.com...
Is there a way to check user input for illegal characters?

For example, a user enters something into a text box and clicks OK.
At that point I'd like to run code such as this:

illegal = Array(\, /, :, *, ?, ", <, >, |)

If Me.TextBox Contains illegal Then
MsgBox "You entered illegal characters. Please try again."
Me.TextBox = Null
Exit Sub
End If

Any suggestions welcome!

Thanks!

You'll have to write your own function - create a new module and paste the
following code in. You will then be able to check IsClean("Whatev er")
Public Function IsClean(strToCh eck) As Boolean

Dim lng As Long
Dim bln As Boolean

If Len(strToCheck) > 0 Then

For lng = 1 To Len(strToCheck)

Select Case Asc(Mid$(strToC heck, lng, 1))

Case 48 To 57
' Numbers 0 to 9

Case 65 To 90
' Letters A to Z

Case 97 To 122
' Letters a to z

Case Else
bln = True
Exit For

End Select

Next lng

End If

IsClean = Not bln

End Function


Nov 12 '05 #6

Private Sub TextBox_AfterUp date()
Dim illegal As Variant, i As Integer, j As Integer

illegal = Array("\", "/", ":", "*", "?", """", _
"<", ">", "|")
For i = 0 to Ubound(illegal)
j = InStr(1, TextBox, illegal(i))
If j > 0 Then
msgbox "illegal character! " & illegal(i)
TextBox = Null
Exit For
End If
Next
End Sub

Here illegal is a variant (all variants are arrays), and I use the Array
function of VB to store the characters above). Note: You have to
delimit everything in the Array function with double quotes. You
delimit one double quote " with 3 double quotes """" (delimit 2 double
quotes "" with 3 double quotes """""). Then you use the InStr function
to check if any of the chars in the array are in the TextBox in a loop.
j would be the position of the illegal char. If j = 0 then there are no
illegal chars. If j > 0 then there is an illegal char and you specify
which illegal char was entered with illegal(i).
Is there a way to check user input for illegal characters?


For example, a user enters something into a text box and clicks OK.
At that point I'd like to run code such as this:

illegal = Array(\, /, :, *, ?, ", <, >, |)

If Me.TextBox Contains illegal Then
MsgBox "You entered illegal characters. Please try again."
Me.TextBox = Null
Exit Sub
End If

Any suggestions welcome!

Thanks!
<<

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #7
Outstanding!

Thanks for the helpful reply.

The issue is that Excel and Word files are generated from the database --
these files use First Name, Last Name and Company in the filename when
automatically saved to disk. If there are illegal characters in one of
those fields, the file export fails for that record.

I've put this validation routine behind the New Record entry form. I'm sure
it could be more elegant, but it works :)

thanks again for the help!

Dim i, j As Integer
Dim varFirst As Variant
Dim varLast As Variant
Dim varCo As Variant
Me.lblFirst.For eColor = 0
Me.lblLast.Fore Color = 0
Me.lblCompany.F oreColor = 0
varNo = Array("\", "/", ":", "*", "?", """", "<", ">", "|")
If IsNull(Me.First Name) = False Then
varFirst = Me.FirstName
For i = 0 To UBound(varNo)
j = InStr(1, varFirst, varNo(i))
If j > 0 Then
MsgBox "Cannot use character:" & Chr(13) & Chr(10) & Chr(13)
& Chr(10) & varNo(i), vbCritical, " Illegal Character"
Me.lblFirst.For eColor = 255
Exit Sub
Exit For
End If
Next
End If
If IsNull(Me.LastN ame) = False Then
varLast = Me.LastName
For i = 0 To UBound(varNo)
j = InStr(1, varLast, varNo(i))
If j > 0 Then
MsgBox "Cannot use character:" & Chr(13) & Chr(10) & Chr(13)
& Chr(10) & varNo(i), vbCritical, " Illegal Character"
Me.lblLast.Fore Color = 255
Exit Sub
Exit For
End If
Next
End If
If IsNull(Me.Compa ny) = False Then
varCo = Me.Company
For i = 0 To UBound(varNo)
j = InStr(1, varCo, varNo(i))
If j > 0 Then
MsgBox "Cannot use character:" & Chr(13) & Chr(10) & Chr(13)
& Chr(10) & varNo(i), vbCritical, " Illegal Character"
Me.lblCompany.F oreColor = 255
Exit Sub
Exit For
End If
Next
End If

"Rich P" <rp*****@aol.co m> wrote in message
news:3f******** *************** @news.frii.net. ..

Private Sub TextBox_AfterUp date()
Dim illegal As Variant, i As Integer, j As Integer

illegal = Array("\", "/", ":", "*", "?", """", _
"<", ">", "|")
For i = 0 to Ubound(illegal)
j = InStr(1, TextBox, illegal(i))
If j > 0 Then
msgbox "illegal character! " & illegal(i)
TextBox = Null
Exit For
End If
Next
End Sub

Here illegal is a variant (all variants are arrays), and I use the Array
function of VB to store the characters above). Note: You have to
delimit everything in the Array function with double quotes. You
delimit one double quote " with 3 double quotes """" (delimit 2 double
quotes "" with 3 double quotes """""). Then you use the InStr function
to check if any of the chars in the array are in the TextBox in a loop.
j would be the position of the illegal char. If j = 0 then there are no
illegal chars. If j > 0 then there is an illegal char and you specify
which illegal char was entered with illegal(i).
Is there a way to check user input for illegal characters?


For example, a user enters something into a text box and clicks OK.
At that point I'd like to run code such as this:

illegal = Array(\, /, :, *, ?, ", <, >, |)

If Me.TextBox Contains illegal Then
MsgBox "You entered illegal characters. Please try again."
Me.TextBox = Null
Exit Sub
End If

Any suggestions welcome!

Thanks!
<<

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #8
bouncer@localho st (Trevor Best) wrote in
<qu************ *************** *****@4ax.com>:
On Wed, 01 Oct 2003 22:05:31 GMT in comp.databases. ms-access,
"deko"
<dj****@hotmai l.com> wrote:
Is there a way to check user input for illegal characters?

For example, a user enters something into a text box and clicks
OK. At that point I'd like to run code such as this:

illegal = Array(\, /, :, *, ?, ", <, >, |)

If Me.TextBox Contains illegal Then
MsgBox "You entered illegal characters. Please try again."
Me.TextBox = Null
Exit Sub
End If

Any suggestions welcome!


what I do in my supplier shortname where I disallow special
characters to aid searching is use the KeyPress event, e.g.

(edited for brevity)
Private Sub txtShortname_Ke yPress(KeyAscii As Integer)
Dim strchar As String
Dim strNoShortName As String
strNoShortName = ",.?/\¬`!"£$%^&*-+='@#~:;|<>¦-_{}[]()`¬'"
If InStr(1, strNoShortName, strchar) Then
KeyAscii = 0
End If
End Sub


Are there any RegExp libraries that can be used in Access?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #9
dX********@bway .net.invalid (David W. Fenton) wrote in news:9408961E8d fentonbwaynetin vali@
24.168.128.90:
Are there any RegExp libraries that can be used in Access?


Of course, but you probably won't use it:

set objRegexp = createobject("S cripting.Regexp ")

--
Ross Presser -- rpresser AT imtek DOT com
"... VB is essentially the modern equivalent of vulgar Latin in 13th Centurary Europe. Understand it, and
you can travel to places you never heard of and still understand some people." -- Alex K. Angelopoulos
Nov 12 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2195
by: jen92103 | last post by:
HI, I want to add the "Did you mean" - Google feature to searches on my website. My website lets users search for a business using different parameters. If there is no match, I want to do a spell check on the entered parameters.
4
11108
by: Georg Vassilopulos | last post by:
Hello! How do I check user input for following formats: I only want to accept floats or integers written as: 232,45 232 242.45 345
5
3832
by: Dave | last post by:
I need to cut out illegal characters in a string submitted from a mobile phone to a web form. I need a way to check for the illegal characters in a textbox. I intend to loop through the text and remove the illegal characters. Is there an equivalent function to c# to chr() in Visual basic? I want the decimal value of a character, like "A" is 65 in ACII2. If there is a equilvalent command does it return ACII2 or unicode? I know there is a...
0
2117
by: Robin Munn | last post by:
I'm developing a simple proof-of-concept Web application, more as a personal programming exercise than anything else, that presents the user with a login form where they can type in a database name, username, and password. I then present them with a text field to type in SQL queries, and hand back a nicely-formatted HTML table with the result of their queries. Basically, just a programming exercise to get my feet wet with the Web...
3
13887
by: Juhan | last post by:
Hi! I have a strange error in a console application that is hosted by IIS 5.0 and invokes a web service hosted on the same machine. A request form the web comes in and it is dispatched to a service class which uses a helper class to create an instance of the automatically generated webservice proxy class. The instance creation fails on this row: _10._0._40._252.ETISXTeeService srv = new
1
2337
by: Shilpa | last post by:
Hi, I have a OpenFileDialog on my windows form whose filter is *.*. I want the users to be able to further filter the files by giving *.doc or *.zip etc in the "file name" field of the dialog (Just like it happens in the open file dialog of MS Word) Currently, if the user enters a wild card character in the file name field, it is throwing an exception with the message "Illegal characters in path". Please let me know how to achieve the...
9
5850
by: chuck | last post by:
I need some help with validating user input. I am writing a C computer program for an intro to C course. Here is the situation. I am creating an application that will do currency conversions. The user will be presented with a list of 5 selections they can make. They will then be prompted for which selection they want to enter (which can only be 1-5, no characters or anything like it). Once they select the number, 1 for Euro, 2 for...
4
2321
by: joesin | last post by:
I recently found a vulnerability on my website that allowed sql injection. I have been trying to write some code that would clean user data but have been running into problems. The validation still works, however so does the injection methods I have used.... These are the examples of code I have tried to use to fix the problem. 1. FrmUserName=replace (FrmUserName, " ' ", "") 2. function stripQuotes(FrmUserName) stripQuotes =...
6
23404
by: uicouic | last post by:
I have a textbox named "txtName" and a button (btnSave) on a webform. After I have typed the illegal characters into the textbox and click "Save", I would like the webform to check for those characters and display a message, "Illegal Characters not allowed". How do I achieve that in JavaScript? Sorry if it seems too simple as I am kinda weak in programming. Thanks.
0
9852
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10902
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10288
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7824
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7014
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5680
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3128
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.