-1

I want to check password when I register in android. It should have some letters (A-Z), some numbers (0-9) and some special characters (-_!@#$%^&*()+=?.,). But it's not working. please help me!

Pattern pattern = Pattern               
                .compile("/^[A-Za-z0-9_.@]+$/u");
jkdev
  • 11,360
  • 15
  • 54
  • 77
tony Hoang
  • 33
  • 6

3 Answers3

0

The usage of / and /u may not belong to java(I haven't seen them from the documentation). What I mean is to change your regex string to be like this:

^[A-Za-z0-9_.@]+$

I test this on my PC, and it works fine. Hope it helps you:)

Lym Zoy
  • 951
  • 10
  • 16
0

Use this as pattern. I hope it will help you.

Pattern pattern = Pattern               
            .compile("([-!#-'*+/-9=?A-Z^-~]+(\.[-!#-'*+/-9=?A-Z^-~]+)*|"([]!#-[^-~ \t]|(\\[\t -~]))+")@[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?(\.[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?)+");

Resource Link: Using a regular expression to validate an email address

Community
  • 1
  • 1
SkyWalker
  • 28,384
  • 14
  • 74
  • 132
0

You can see more and best explanation here

http://www.mkyong.com/regular-expressions/how-to-validate-password-with-regular-expression/

Short answer:

PASSWORD_PATTERN = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})"
thuongle
  • 537
  • 6
  • 10