Check textbox contians "DWD" followed by 5 HEX characters?

Posted on 2009-04-23
Last Modified: 2012-05-06

I'm using the below code to check my textbox has a value of "DWD" and 5 hex characters, e.g. DWD00A0A. It doesn't seem to work with the (5) after the HEX part of the validation, although it does work without the (5) in there, although it means users can enter more than 5 HEX characters.

can anyone see why this is not working?

If Not Regex.IsMatch(Respond_DWD.Text, "^[D]{1}[W]{1}[D]{1}[A-Fa-f0-9](5)$") Then

            MessageBox.Show("Please enter users workstation id in the correct format (E.G. DWD1A2B3)." & vbNewLine & vbNewLine & "E.G. DWD00A0A")

End If

Open in new window

Question by:m0tSiE
    LVL 39

    Accepted Solution

    What about:

    Regex.IsMatch(Respond_DWD.Text, "^DWD[A-Fa-f0-9]{5}$")

    Author Comment

    Yeah, I just realised I used rounded brackets on the number instead of the other ones.


    Author Closing Comment

    Cheers! :D
    LVL 39

    Expert Comment

    Note also the your "[D]{1}[W]{1}[D]{1}" is more easily readable as "DWD"...

    glad to be of some help :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    This video teaches viewers about errors in exception handling.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    779 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

    12 Experts available now in Live!

    Get 1:1 Help Now