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

Posted on 2005-05-02
Last Modified: 2008-09-24
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.

Question by:HStrix
    LVL 19

    Accepted Solution

    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

    r1.Match (....)

    so on...


    Author Comment

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



    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now