Search code examples
javaregexperlpasswordskeycloak-services

How to exclude space as input on my regex


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

My regex above works fine except it accepts space as input. How can i exclude spaces on my regex?

Any Perl related regex implementation will be fine. Thanks


Solution

  • Change

    .{8,15}
    

    to

    [^ ]{8,15}                       # No spaces.
    

    or

    \S{8,15}                         # No whitespace.
    

    or

    [A-Za-z0-9#?!@$%^&*\-]{8,15}     # Only allow specific characters.