Java regex: check if word has non alphanumeric characters
Change your regex to:
.*\\W+.*
This is the expresion you are looking for:
"^[a-zA-Z0-9]+$"
When it evaluates to false that means does not match so that mean you found what you wanted.
It's 2016 or later and you should think about international strings from other alphabets than just Latin. The frequently cited [^a-zA-Z]
will not match in that case. There are better ways in Java now:
[^\\p{IsAlphabetic}^\\p{IsDigit}]
See the reference (section "Classes for Unicode scripts, blocks, categories and binary properties"). There's also this answer that I found helpful.