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
Post a Comment