0

I am trying to use RegEx to validate user input, the input format should be :

partA/partB

partA: number(number of digit is a variable)

partB: 2 digit number

I use the workable expression in Flex in vb.net, but not work.

My code is like follows:

    If Not Regex.Match(ItemNo.Text, "/\d\{2\}$").Success Then
       ItemNo.Text = "Invalid Contract No."
       ItemNo.Focus()
       Return
End If

Could anybody help me on this? Thanks.

1
  • what you are actually trying to achieve? what is your input? Commented Sep 25, 2014 at 5:42

2 Answers 2

1

Just change your regex to,

^\d+/\d{2}$

So the code would be,

If Not Regex.Match(ItemNo.Text, "^\d+/\d{2}$").Success Then
       ItemNo.Text = "Invalid Contract No."
       ItemNo.Focus()
       Return
End If

\d+ matches one or more digits where \d{2} matches exactly two digits.

Sign up to request clarification or add additional context in comments.

Comments

1
^\d*\/\d{2}$

You should try this.This will get vairable forst partand 2 digit second part.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.