Ok, so here's the code I'm using ATM:
8< - - - - - - - - -
// InputFilter for file names
// use like this:
//
// edittext.setFilters(new InputFilter[]{cFilenameInputFilter});
static final InputFilter cFilenameInputFilter = new InputFilter()
{
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend)
{
for (int i = start; i < end; i++)
{
int ch = source.charAt(i);
boolean is_unicode_punctuation = false;
switch (Character.getType(ch)) {
case Character.CURRENCY_SYMBOL:
case Character.CONNECTOR_PUNCTUATION:
case Character.FINAL_QUOTE_PUNCTUATION:
case Character.INITIAL_QUOTE_PUNCTUATION:
case Character.DASH_PUNCTUATION:
case Character.START_PUNCTUATION:
case Character.END_PUNCTUATION:
case Character.OTHER_PUNCTUATION:
is_unicode_punctuation = true;
break;
}
// check against Forbidden chars:
// 'reverse solidus':
http://blogs.msdn.com/b/michkap/archive/2005/10/12/479561.
final char reverse_solidus = 0x005c;
final String forbidden_chars = "|?*<>:\"+[]/\\" + reverse_solidus;
boolean is_allowed = (forbidden_chars.indexOf(ch) == -1);
boolean is_valid_char = is_allowed &&
(Character.isLetterOrDigit(ch) || is_unicode_punctuation);
if(is_valid_char == false)
{
return ""; // ops
}
}
return null; // go on, char should be fine
}
};
8< - - - - - - - - -
best
--
Mathieu
On Aug 30, 1:22 pm, Daniel Drozdzewski <[email protected]>
wrote:
> On 30 August 2011 12:17,bdk<[email protected]> wrote:
>
> > A possibly catch-all solution:
>
> > http://download.oracle.com/javase/tutorial/i18n/text/charintro.html
>
> > :)
>
> Indeed!
> That should work just fine and avoids use of RegEx.
>
> Thanks!
>
> --
> Daniel
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en