You must Sign In to post a response.
  • Category: ASP.Net MVC

    Regex for Password Must be contain at least 6 characters, at least 2 number 2 character

    hi
    I have stuck following point .
    Regex for Password Must be contain at least 6 characters, at least 2 number and 2 characters in any order.
    I use following Regex expressing.

    "^.*(?=.{6,50})^(?=.*\d{2,})(.*?[a-zA-Z]){2,}.*$"

    but they give following result like this. "11qqww, ww1122qq2, ww22fe" . means they check continuous 2 latter and 2 digit.
    but i want result like this "1q2w3ew, qq2w3e4, q1w3e2".

    so please guide us ,how can i do this .

    Thank you,
    Santosh Deshmukh
  • #764815

    Hi Santosh,
    Try following code:
    Regex myRegex = new Regex("(?=^.{6,}$)(?=(.*\\d){2})(?=(.*[A-Za-z]){2})");
    var match= myRegex.Match("1q2w3ew");
    var newInput = match.Success;

    Hope it helps.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #764820
    Hai Santosh,
    You can tweak your regex a little and then test it. Below is the link where you can test your regex online and validate:

    https://regex101.com/

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #764846
    I have not go through it but still you can check below regular expression
    ^.*(?=.{6,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$
    OR
    /^(?=(?:.*[a-z]){2})(?=(?:.*[A-Z]){2})(?=(?:.*\d){2})(?=(?:.*[!@#$%^&*-]){2}).{15,}$/

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


Sign In to post your comments