C#後臺代碼使用正則表達式判斷是否符合要求

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位");
                }
            }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章