C#後臺使用正則表達式:
string pattern = @"^[0-9a-zA-Z_]{1,10}$";//字母數字下劃線,1到10位
bool result = false;
if (!string.IsNullOrEmpty(this.txtNewPwd.Text.Trim()))
{
result = System.Text.RegularExpressions.Regex.IsMatch(this.txtNewPwd.Text, pattern);
if (!result)
{
throw new Exception("密碼爲字母數字下劃線組合且最多10位");
}
}