Combining these two Regular Expressions into one

前端 未结 6 1711
眼角桃花
眼角桃花 2020-12-16 17:38

I have the following in C#:

public static bool IsAlphaAndNumeric(string s)
{
    return Regex.IsMatch(s, @\"[a-zA-Z]+\") 
        && Regex.IsMatch(s,         


        
6条回答
  •  一个人的身影
    2020-12-16 18:09

    private static readonly Regex _regex = new Regex(
        @"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$", RegexOptions.Compiled);
    
    public static bool IsAlphaAndNumeric(string s)
    {
        return _regex.IsMatch(s);
    }
    

    If you want to ignore case you could use RegexOptions.Compiled | RegexOptions.IgnoreCase.

提交回复
热议问题