Reputation: 75
String pattern = "([a-zA-Z]{1,2}-[1-9]{1,4}-[a-zA-Z]{2,3})";
if (CheckMandatory())
{
try
{
if (ViewState["currentEditDataID"] == null || ViewState["currentEditDataID"] == "")
{
if (txtNoPolisi.Text.Length < 12 && Regex.IsMatch(txtNoPolisi.Text,pattern))
{
save();
}
i have the pattern above so that the input should be like b-1234-abc / bb-1234-abc
but when i input bbb-1234-asda it doesn't show error
Upvotes: 1
Views: 50
Reputation: 150238
Sure, it matches the middle of your string
bbb-1234-asda
You need to specify that it needs to match the beginning and end of string to avoid that.
(^[a-zA-Z]{1,2}-[1-9]{1,4}-[a-zA-Z]{2,3}$)
Upvotes: 2