1.必須為大寫字母,小寫字母,數字和符號的至少其中3種組合 The new password should contain any three of different syntax which is Upper Case Character, Lower Case Character, Numeral and Symbol.
[RegularExpression(@"^((?=.*d)(?=.*[A-Z])(?=.*[-+?*$[]^.()|`!@#%&_=:;',/])|(?=.*d)(?=.*[a-z])(?=.*[A-Z])|(?=.*d)(?=.*[a-z])(?=.*[-+?*$[]^.()|`!@#%&_=:;',/])|(?=.*[a-z])(?=.*[A-Z])(?=.*[-+?*$[]^.()|`!@#%&_=:;',/])).+$", ErrorMessage = DisplayMsgs.InvalidPassword)] public string NewPassword { get; set; }
2.必須為大寫字母,小寫字母,數字,長度須為6~8位 RegularExpression(@"[A-Za-z0-9]{6,8}", ErrorMessage = DisplayMsgs.InvalidEncryptKey)] [Required(ErrorMessage = "Encrypt Key" + DisplayMsgs.RequiredInput)] public String EncryKey { get; set; }
string regex = @"^[A-Za-z0-9]{6,8}$"; if (string.IsNullOrEmpty(request.EncryptionKey) || !Regex.IsMatch(request.EncryptionKey.Trim(), regex)) { response.Status = ResponseStatuses.InvalidEncryKey; return response; }
3.漢字
string text = "是不是汉字,ABC,keleyi.com";
for (int i = 0; i < text.Length; i++)
{
if (Regex.IsMatch(text[i].ToString(), @"[u4e00-u9fbb]+{1}quot;))
Console.WriteLine("是汉字");
else
Console.WriteLine("不是汉字");
} 用ASCII码判断 string text = "是不是汉字,ABC,柯乐义";
for (int i = 0; i < text.Length; i++)
{
if ((int)text[i] > 127)
Console.WriteLine("是汉字");
else
Console.WriteLine("不是汉字");
}