VB.Net: check a string for captitals, numbers and special characters

Hello experts,
in my Vb.Net web application
I'ld like to check a string if it contains at least one of the following characters
- a capital
- a small character "a","b" ...
- a number
- a special character: #, *, !, %, ?, +, <, >, /

If anyone knows a solution,
please supply an appropriate code snippet.

   Thank you very much for any help.

   HStrix
 
HStrixAsked:
Who is Participating?
 
arif_eqbalCommented:
Hi HStrix
Well it seems you want to look for everything in your string.
You are searching for small letters, capital letters, numbers and special characters as well. I think it could be the other way round I mean you should look for things that you do not expect to occur as that list would be smaller. Here you are almost certain that one of the above letters would anyway occur.

Anyway this is just an eg how you can achieve what you want, the key is RegularExpressions...


        Dim r As New Regex("[a-zA-Z0-9#*!]") 'Look for these
        Dim m As Match = r.Match("Some String Where we need to Find the pattern") 'In This
        If m.Success Then
            'We found either a small letter or a capital letter or a numeric value
        End If



Here we are looking for a-z (small alphabets) A-Z (Capitals) 0-9 (Numbers) and three literals # * and !
you can increase the list like this ("[a-zA-Z0-9#*!%<>+?]")  

Now this is looking for all these chars at one go, in case you want to look one by one you can split

Dim r1 As New Regex("[a-z]") 'Look for small letters only
Dim r2 As New Regex("[A-Z]") 'lok for capitals

then...
r1.Match (....)
r2.Match(...)

so on...

0
 
HStrixAuthor Commented:
Thank you very much arif_eqbal,
that's exactly what I was looking for.

  HStrix

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.