c#中的密码验证 [英] Password validation in c#

查看:78
本文介绍了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的字符串,包含至少一个数字并包含至少一个小写字母或大写字母< br $>


(?= ^。{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,}


这篇关于c#中的密码验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆