Checking for invalid characters within a string

  • Thread starter Thread starter Heath P. Dillon
  • Start date Start date
H

Heath P. Dillon

Hi,

I have a situation where I have a remote system that can only contain the
basic A-Z 0-9 characters. Anything outside of those will cause an error in
the remote system which I have to solve by cleaning my data first.

In a normal situation I would just look for say the invalid character using
instr, however there as so many possible character that are invalid(as there
are so few valid ones) that just seems like an impossible task.

Is there a way to easily check the string to make sure it only contains
A-Z/0-9, rather than checking for a specific invalid character.

Thanks
 
Hi,

I have a situation where I have a remote system that can only contain the
basic A-Z 0-9 characters. Anything outside of those will cause an error in
the remote system which I have to solve by cleaning my data first.

In a normal situation I would just look for say the invalid character using
instr, however there as so many possible character that are invalid(as there
are so few valid ones) that just seems like an impossible task.

Is there a way to easily check the string to make sure it only contains
A-Z/0-9, rather than checking for a specific invalid character.

Thanks

System.Text.RegularExpressions


If Regex.IsMatch (yourString, "^[A-Z0-9]+$") Then
' Do you stuff
End If

HTH
 
If you can only check the string, Tom's solution works. If you can check on
input, you can get the byte value of the character entered and refuse
anything other than numbers and letters. You then avoid the problem string
altogether. Since you say remote system, you probably do not mean an app you
created that someone is using remotely, which negates the suggestion of
capturing keystrokes.

If you can capture keystrokes (next version of software?), valid characters
are 48-57 (0-9), 65-90 (A-Z) and 97-122 (a-z). A complex if, simple select
case or even Regex can be used here.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

*********************************************
| Think outside the box |
*********************************************
 
If you can only check the string, Tom's solution works. If you can check on
input, you can get the byte value of the character entered and refuse
anything other than numbers and letters. You then avoid the problem string
altogether. Since you say remote system, you probably do not mean an app you
created that someone is using remotely, which negates the suggestion of
capturing keystrokes.

If you can capture keystrokes (next version of software?), valid characters
are 48-57 (0-9), 65-90 (A-Z) and 97-122 (a-z). A complex if, simple select
case or even Regex can be used here.

You know it's sort of funny... But, I've been doing middle-tier work for so
long now (at least the last 3 years) - that I don't even think of the GUI side
anymore :)
 
Thanks guys.

The remote system, is actually a datadump, not a users input. I process the
data and clean it for another remote application which has the char limits.


Thanks for you assistance.
 
Back
Top