-1

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?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
arthos455
  • 3
  • 1
  • 6

1 Answers1

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