Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5205
  • Last Modified:

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
 
0
HStrix
Asked:
HStrix
1 Solution
 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now