Hum ... just program it yourself using String.chatAt ( int ), it's pretty simple ...
Iterate through all char in a string using a position index, and then compare it using the fact that ASCII characters 0 through 9, a through z and A through Z use sequential codes, so you only need to check that the character x numerically checks one of the conditions:
- between '0' and '9'
- between 'a' and 'z'
- between 'A and' Z '
- space ''
- hyphen '-'
Here is an example of the base code (using CharSequence, which allows passing String as well as StringBuilder as arg):
public boolean isValidChar(CharSequence seq) { int len = seq.length(); for(int i=0;i<len;i++) { char c = seq.charAt(i); // Test for all positive cases if('0'<=c && c<='9') continue; if('a'<=c && c<='z') continue; if('A'<=c && c<='Z') continue; if(c==' ') continue; if(c=='-') continue; // ... insert more positive character tests here // If we get here, we had an invalid char, fail right away return false; } // All seen chars were valid, succeed return true; }
source share