Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
hi ,

i need a help in following query.

must contains characters
must contains one digit from 0-9
must contains one special symbols in the list "@#$%"
length at least 6 characters and maximum of 20

I want regex vadlidator for above conditions.

I am trying below javascript but it didnt work for me

XML
<script language="javascript" type="text/javascript">
    function validate() {



           re= /^([a-zA-Z+]+[0-9+]+[&@!#+]+)$/ ;
        if (!re.test(document.getElementById("txtNewPassword").value)) {
            alert("Your new password does not comply with the password policy" + '\n' + "" + '\n' +  "-must contain at least 6 characters" + '\n' + "-must contain at least one number (0-9)" + '\n' + "-must contain at least one character" + '\n' + "-must contain at least one special character (@#$%)");
                       document.getElementById("txtNewPassword").focus();
            return false;
        }


        else {
            return true;
        }
    }
</script>



Above function is working fine on IE 8 but not on IE7 and IE6
Posted
Updated 6-Nov-13 1:14am
v2
Comments
bbirajdar 6-Nov-13 6:17am    
And how will your validation code work if the user disables javascript in the browser ?
Dhaval Patel 6-Nov-13 6:26am    
Is there any sequence of alphabets, digits and symbols in password text? Or they can appear in any sequence?
Pro86 6-Nov-13 6:29am    
they can appear in any sequence
Pro86 6-Nov-13 6:54am    
above function is running but only on IE 8

May be you can look here for getting the right Regular Expressions as this article explains clearly the way to use Regular Expressions Pattern for specific names.

http://www.mkyong.com/regular-expressions/10-java-regular-expression-examples-you-should-know/[^]
 
Share this answer
 
Below is my new working javascript function

XML
<script type = "text/javascript">

    function validate() {
        x = document.getElementById("txtNewPassword").value;
        if ((/[a-z]/g.test(x)) && (/[0-9]/g.test(x)) && (/[@#$%]/g.test(x)) && (x.length >= 6) && (x.length <= 20)) {
                        return true;
        }
        else {
                        return false;

        }
    }

</script>




below URL help me

http://www.codingforums.com/showthread.php?t=179504[^]
 
Share this answer
 
hi,

follow this link. You will have your answer.

http://jsfiddle.net/evCN6/1/

Thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900