Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is my regexp for password validation for a Java application:

^.*(?=.{8,})(?=..*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$

Can anyone tell me how to do regexp check for space, tab, carriage return, etc.?

1 Answer

0 votes
by (19.7k points)

Please try the below:

^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\S+$).{8,}$

Here’s the explanation for it:

^                 # start-of-string

(?=.*[0-9])       # a digit must occur at least once

(?=.*[a-z])       # a lower case letter must occur at least once

(?=.*[A-Z])       # an upper case letter must occur at least once

(?=.*[@#$%^&+=])  # a special character must occur at least once

(?=\S+$)          # no whitespace allowed in the entire string

.{8,}             # anything, at least eight places though

$                 # end-of-string

Interested in Java? Check out this Java tutorial by Intellipaat.  

Related questions

0 votes
1 answer
asked Mar 4, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
asked Feb 8, 2021 in Python by ashely (50.2k points)
0 votes
1 answer
0 votes
1 answer
asked Apr 28, 2021 in Java by sheela_singh (9.5k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...