You must Sign In to post a response.
  • Category: .NET

    Regular expression validation

    Need a regular expression for at least two (2) of the following three (3) cases;
    a. Upper (e.g., A, B, C, ...Z) and lower case letters (e.g., a, b, c, ...z)
    b. Numerals (e.g., 1, 2, 3, ...9)
    c. Non-alphanumeric (special characters) (e.g., ?,!,%,$,#, etc)
  • #762032
    Hello Techsoft,

    You can refer the below code :

    <input type="text" id="textbox1" value="" />
    <input type="button" id="Validate" onclick="ValidatePassword()" value="Validate" />
    <script type="text/javascript">
    function ValidatePassword() {
    var regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$@!%&*?])[A-Za-z\d#$@!%&*?]{10,12}$/;
    var txt = document.getElementById("textbox1");
    if (!regex.test(txt.value)) {
    alert("Password strength is not good.");
    } else {
    alert("Password strength is good.");
    }
    }
    </script>


    Valid password e.g : Pass@1234


    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762033
    Hello Techsoft,

    Minimum 8 characters at least 1 Alphabet and 1 Number :
    "^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{8,}$"

    Minimum 8 characters at least 1 Alphabet, 1 Number and 1 Special Character :
    "^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{8,}$"

    Minimum 8 characters at least 1 Uppercase Alphabet, 1 Lowercase Alphabet and 1 Number :
    "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$"

    Minimum 8 characters at least 1 Uppercase Alphabet, 1 Lowercase Alphabet, 1 Number and 1 Special Character :
    "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}"

    Minimum 8 and Maximum 10 characters at least 1 Uppercase Alphabet, 1 Lowercase Alphabet, 1 Number and 1 Special Character :
    "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,10}"


    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762034
    it should work with pass@123 or 1234567@
    ie,
    at least two (2) of the following three (3) cases;
    a. Upper (e.g., A, B, C, ...Z) and lower case letters (e.g., a, b, c, ...z)
    b. Numerals (e.g., 1, 2, 3, ...9)
    c. Non-alphanumeric (special characters) (e.g., ?,!,%,$,#, etc)

  • #762035
    how to use or condition?

  • #762037
    Hello Techsoft,

    I have provided you the regular expression you just have to replace it here :

    <input type="text" id="textbox1" value="" />
    <input type="button" id="Validate" onclick="ValidatePassword()" value="Validate" />
    <script type="text/javascript">
    function ValidatePassword() {
    var regex = /^your regular expression$/;
    var txt = document.getElementById("textbox1");
    if (!regex.test(txt.value)) {
    alert("Password strength is not good.");
    } else {
    alert("Password strength is good.");
    }
    }
    </script>

    Hope you understood.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"


Sign In to post your comments