3

I looking for this but i can't found a good solution.

I found a solution but visual studio get an error

var regexItem = new Regex(@"^[a-zA-Z0-9\_]+$);

And it's my condition:

if (regexItem.IsMatch(name))
{
     //...
}
Community
  • 1
  • 1
distance
  • 824
  • 7
  • 19

1 Answers1

9

Just include the pattern for dash and point inside the character class. And it's safe to put - at the last or at the first inside the character class.

new Regex(@"^[a-zA-Z0-9_.-]+$");
Avinash Raj
  • 166,785
  • 24
  • 204
  • 249