c#中的密码验证

问题描述:

HI all



我有验证密码。密码长度应为最小6,并且应包含至少一位数字和至少一个字母。



请帮帮我



我尝试了以下功能,但它失败了

HI all

I have validate password. password length should be min 6 and should contain atleast one digit and atleast one alphabet.

Please help me out

I have tried following function but it fails

public bool CheckPassword(string password)
        {
            //string MatchEmailPattern = "(?=.{6,})[a-zA-Z0-9]+[^a-zA-Z]+|[^a-zA-Z]+[a-zA-Z]+";
            string MatchEmailPattern = "^[a-zA-Z0-9]+$";

                if (password != null) return Regex.IsMatch(password, MatchEmailPattern);
                else return false;


        }

;

if (密码!= null return Regex.IsMatch(password,MatchEmailPattern);
else return false ;


}
"; if (password != null) return Regex.IsMatch(password, MatchEmailPattern); else return false; }


请参考此回答 [ ^ ] -Regular Expressions for password
Please refer this answer[^]-Regular Expressions for password


可以使用以下正则表达式匹配长度至少为6的字符串,包含至少一个数字并包含至少一个小写字母或大写字母


(?= ^。{6,}
The following regular expression can be used to match a string whose length is at least 6, contains at least one digit and contains at least one lower case or upper case alphabet

(?=^.{6,}