Sarkiroka's solution is correct, but forgot the dash, and the dot must be escaped.
You must add as \ to avoid this, but remember that in Java, the backslash itself is used to exit, so if you write a regular expression in a java file, you should write
String regex = "[a-zA-Z0-9\\._\\-]{3,}";
Note the double backslash.
source share