How to: Strip Invalid Characters from a String
String CleanInput(string strIn)
{
// Replace invalid characters with empty strings.
return Regex.Replace(strIn, @"[^\w\.@-]", "");
}
The regular expression "^[0-9]*$" only matches strings that consist entirely of digits.
Othe useful expressions:
{n,} - matches at leas n times
{n,}? - nongreedy {n,} quantifier
\s - only spaces