I'm currently creating an app with a login screen. I've got everything setup but i want to make the password follow a normal set of rules: The password must have a special character (!, @, #, $, %...), A number, and a uppercase letter. I'm pretty sure i know how to do 2 of the 3. The problem im having is making an if statement to check to see if the password has a special character. I was wondering if there is a simple way to do this. Any solution to do this?
Asked
Active
Viewed 1,548 times
-1

OneCricketeer
- 179,855
- 19
- 132
- 245

arthos455
- 3
- 1
- 6
-
you want to do this android side? – mehrdad khosravi Apr 12 '16 at 14:30
-
3You can create a regex, something similar to: http://stackoverflow.com/questions/5142103/regex-to-validate-password-strength – buczek Apr 12 '16 at 14:31
-
i used .net to server side and Microsoft have class for validate any thing like password – mehrdad khosravi Apr 12 '16 at 14:35
-
@mehrdad Yes id like to do this all through within the main activity itself. – arthos455 Apr 12 '16 at 14:35
1 Answers
1
I am using the given method for checking special Character. you can replace it's regex
according to your need.
public Boolean isSpecialCharAvailable(String s) {
//int counter =0;
if (s == null || s.trim().isEmpty()) {
return false;
}
Pattern p = Pattern.compile("[^A-Za-z0-9]");//replace this with your needs
Matcher m = p.matcher(s);
// boolean b = m.matches();
boolean b = m.find();
if (b == true)
return true;
else
return false;
}

Zar E Ahmer
- 33,936
- 20
- 234
- 300