Mount Regex to validate password

Asked

Viewed 6,138 times

2

someone would know to set up a regex to validate numerical and alphabetic sequences of at least 4 digits, like : 1111/1234/abcd/4321/dcba?

  • Do you want to validate whether they are sequences or the same? I don’t quite understand.

  • I want to validate both, for example, if the guy writes "1111", I can not authorize this password because they are equal digits, if it is "1234" or "abcd" I can not, I do not know to use regex, I had done by values of an array, but saw that in good practice the ideal is to use regex

3 answers

6


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

"^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{4,}$"
  • guy tried it here and it didn’t work very well, I found one that worked a little better "^(?=.\d)(?=.[a-za-Z])(?!. *[ W_x7B-xff]). {4,15}$"

  • Okay, if you found one that fits better, great, the idea is you can solve your problem. Hug.

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: https://regex101.com/

-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.

  • http://www.codigoexpresso.com.br/Home/Postagem/52

  • 3

    This ai does not look javascript, and the question tag is JAVASCRIPT.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.