java string match pattern with a-z , A-Z, 0-9 and some special char -


i need write method match a-z, a-z , 0-9 , special charecter . , @, _, -.

i have written confused spcl characters.

public static boolean isalfanumeric(string src) {     if (src == null) {         return false;     }     if (src.matches("[a-za-z0-9]*")) {         return true;     }     return false; } 

try 1 -

public static boolean isalfanumeric(string src) {     if (src == null) {         return false;     }     if (src.matches("[\\w@,-]*")) {         return true;     }     return false; } 

put required special characters inside square brackets. info - \w covers word characters includes alphabets in both cases, digits , underscore character. hope helpful.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -