1

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

1 Answers1

8

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
  • 172,303
  • 28
  • 230
  • 274