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

Posted on 2009-04-23
Medium Priority
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
  • 2
  • 2
LVL 39

Accepted Solution

abel earned 2000 total points
ID: 24214143
What about:

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

Author Comment

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


Author Closing Comment

ID: 31573725
Cheers! :D
LVL 39

Expert Comment

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

glad to be of some help :)

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses
Course of the Month15 days, 13 hours left to enroll

850 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