Prasenjit Maity
Prasenjit Maity

Reputation: 69

C# Regular Expression Customize

I'm using C# .Net in Visual Studio. I want to create a regular expression for these (Examples: AA-01, AC-02, AZ-09). That is (two Uppercase Character - Two Numeric Digit).

I tried code below but I'm not getting proper result

using System.Text.RegularExpressions;
...
if (new Regex(@"^([A-Z])-([0-9])$").IsMatch(this.textBoxItemCode.Text.Trim()) == false)    
{    
    MessageBox.Show("Please enter Proper Item 
    textBoxItemCode.Focus();
}

Upvotes: 0

Views: 180

Answers (1)

Haytam
Haytam

Reputation: 4733

You were on the right path, your regex expression only handles 1 uppercase character and 1 number/digit, you should change it to:

^([A-Z]{2})-([0-9]{2})$

Test it here: https://regex101.com/r/KwIDtp/1
More informations: Match Exactly n Times: {n}

Upvotes: 4

Related Questions