V
V
Vlad_Radigin2018-05-05 13:00:58
Java
Vlad_Radigin, 2018-05-05 13:00:58

How to check if Cyrillic is present in a string?

How to check for Cyrillic?
For example, if the line contains Cyrillic, then it will display an error, but if everything is Latin, then there will be no error?
How to do a similar check in java?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2018-05-05
@Vlad_Radigin

String s = "Тест";
boolean cyrillic = s.chars()
                    .mapToObj(UnicodeBlock::of)
                    .anyMatch(b -> b.equals(UnicodeBlock.CYRILLIC));

A
alexalexes, 2018-05-05
@alexalexes

Use regular expression string validation.
In your case, you need to look not for forbidden characters, but on the contrary, check that the string contains only allowed characters.
https://ru.stackoverflow.com/questions/569779/%D0%...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question