我有一个 TextBox ,其中介绍了Text(三个名字)。我希望这个文本框只接受UNICODE格式的字符!
这是我的(错误的)ASCII格式代码:
if (!Regex.IsMatch(txtThreeNames.Text, "[a-zA-Z]^"))
{
return "Three names, must be a string !";
}
答案 0 :(得分:0)
试试这个:
public static bool IsASCII(this string value)
{
// ASCII encoding replaces non-ascii with question marks, so we use UTF8 to see if multi-byte sequences are there
return Encoding.UTF8.GetByteCount(value) == value.Length;
}