We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Similar logic implemented without looping, using Regular Expressions in Java.
staticintminimumNumber(intn,Stringpassword){intlc=0,uc=0,no=0,sc=0;intsum=0;Stringlowercase=".*[a-z]+.*";Stringuppercase=".*[A-Z]+.*";Stringnum=".*[0-9]+.*";Stringspecialchar=".*[-!@#$%^&*()+]+.*";//Regex for pattern matchingif(!(password.matches(lowercase)))lc++;//if there is no match to a lowercase,"lc" is increased by 1.if(!(password.matches(uppercase)))uc++;//if there is no match to an uppercase,"uc" is increased by 1.if(!(password.matches(num)))no++;//if there is no match to a number,"no" is increased by 1.if(!(password.matches(specialchar)))sc++;//if there is no match to a specialCharacter,"sc" is increased by 1.sum=lc+uc+sc+no;return(sum>(6-n))?sum:(6-n);}
Strong Password
You are viewing a single comment's thread. Return to all comments →
Similar logic implemented without looping, using Regular Expressions in Java.