views:

38

answers:

3

if i create a text filter in the following manner

class AlphaTextFilter extends TextFilter {

    public char convert(char c, int status) {
        if (!validate(c))
                return 0;
        return c;
    }

    public boolean validate(char c) {
        return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
    }
}

will it work if the code is run on a device with some language other than english...? how can i make a localized....?

A: 

Yes, I believe so.

A char is a char no matter what locale you're in. It's all Unicode anyway, so there shouldn't be any sort of localisation issues.

Christopher
+2  A: 

What about using something like CharacterUtilities.isLetter() to check if it's a letter?

Marc Novakowski
A: 

That depends on what your definition of "work" is. If by "work" you mean accepts only [a-zA-Z], then yes.

If you mean would it meet the expectations of international users who expect to be using alphabetic, syllabic or ideographic characters (or "letters" in more common usage), then no. Most platforms now offer some mechanism for identifying the unicode character class, and most newer regex engines support matching based on unicode character classes. In your case, \p{letter} would appear to be the most appropriate character class.

JasonTrue