利用正则表达式验证汉字和英文,阿拉伯数字

来源:互联网 发布:办公室优化改进改善 编辑:程序博客网 时间:2024/06/06 08:29

利用正则表达式验证汉字和英文,阿拉伯数字

 

System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("^[/u4e00-/u9fa5]+$ || ^[a-zA-Z0-9]+$"); //验证汉字和英文,阿拉伯数字
if (reg.Match(textBox5.Text.ToString()).Success)
{
    //遍历ArrayList中的所有道路信息
    foreach (object o in m_list)
    {
        //获得道路名称各汉字拼音首字母缩写,及阿拉伯数字
        //string strRoadName = GetSpell(o.ToString()).ToLower();
        string strtxtRoadName = textBox5.Text.ToLower();
        //根据拼音进行匹配(利用Contain和Substring函数进行判定)
        if ( strtxtRoadName.Substring(0, strtxtRoadName.Length) == strtxtRoadName)
        {
            listBox2.Items.Add(o);
        }
    }
}
else
{
    //当TextBox为空时显示所有数据
    return;
}