Mount RegEx to validate password

1

Someone would know how to mount a regex to validate numeric and alphabetic sequences of at least 4 digits, type: 1111/1234 / abcd / 4321 / dcba?

    
asked by anonymous 22.10.2015 / 15:37

3 answers

4

At least 4 characters, at least 1 letter and 1 number:

"^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{4,}$"
    
22.10.2015 / 15:43
3

If you want to validate if the password has 4 characters containing letters or numbers only. You can use this Regex:

^[^\W_]{4}$

If you want to test, I recommend this site: link

    
22.10.2015 / 15:44
-3

private string getRegex()
    {
        string regex = "^.*(?=.{" + this.TamanhoMinimo.ToString() + ","+this.TamanhoMaximo.ToString()+"})";


        if (SenhaForte)
        {
            regex += "(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])";
            if (this.CaracterEspecial)
            {
                regex += "(?=.*[@#$%^&+=])";
            }
        }
        else
        {
            regex += "(?=.*[a-zA-Z0-9@#$%^&+=])";
        }

        regex += ".*$";

        return regex;
    }

//Letras maiúsculas, minusculas, caracteres especiais (@#$%^&+=) e numeros.

    
25.02.2017 / 00:04