1

I looked for a solution online, but I didn't find any.

I want to validate input string and check if it contains only ALLOWED characters.

My problem is, that I have "special" alphabet which contains "ěščřžýáí".

For normal English alphabet I can use regex like this A-Za-z.

But what to use for quick check in my language?

My language contains following chars:

String ALLOWED_CHARS = "AÁBCČDĎEÉĚFGHChIÍJKLMNŇOÓPQRŘSŠTŤUÚŮVWXYÝZŽaábcčdďeéěfghchiíjklmnňoópqrřsštťuúůvwxyýzž";

Thank you for your advice!

3
  • Possible duplicate of Java regex for support Unicode? Commented Nov 28, 2015 at 16:23
  • 1
    @ashutosh I don't want allow chinase character. Commented Nov 28, 2015 at 16:24
  • try to read a couple of answers there, I am pretty sure you will find your answer. Commented Nov 28, 2015 at 16:29

1 Answer 1

3

You should use string.matches("[" + ALLOWED_CHARS +"]*") to this check, for example:

String ALLOWED_CHARS = "AÁBCČDĎEÉĚFGHChIÍJKLMNŇOÓPQRŘSŠTŤUÚŮVWXYÝZŽaábcčdďeéěfghchiíjklmnňoópqrřsštťuúůvwxyýzž";
String s1 = "ĎE88É"; 
boolean flag1 = s1.matches("[" + ALLOWED_CHARS +"]*"); // false
String s2 = "ĎEÉ";
boolean flag2 = s2.matches("[" + ALLOWED_CHARS +"]*"); // true
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.