Android Question сheck the presence of Cyrillic or Kazakh characters in a string

Valeriy Lakhtin

Member
Licensed User
how to check the presence of Cyrillic characters in string or how to check the presence of unwanted characters in the phone number
 

Valeriy Lakhtin

Member
Licensed User
Thank you very much Erel. But for working Regex(...), do you need to use an additional library?
How can you do a similar check for the letters with Cyrillic in string?
 
Upvote 0

Valeriy Lakhtin

Member
Licensed User
Then check the Cyrillic alphabet would look like?

Sub CheckCyrillic(s AsString) As Boolean
Return Regex.IsMatch(@"S""[\p{IsCyrillic}\p{P}\p{N}\s]*""", s)
End Sub

or more simple

Sub CheckCyrillic(s AsString) As Boolean
Return Regex.IsMatch("[\p{IsCyrillic}]", s)
End Sub
 
Last edited:
Upvote 0

Valeriy Lakhtin

Member
Licensed User
Trying to get to work the universal function to determine the characters in a string. It is nothing is impossible, even for a phone number does not work. Perhaps the problem is the syntax I do not know how right use the brackets and an asterisk.

B4X:
Sub CheckSymvol(s As String) As Int
Dim IDCyr As Int, IDNum As Int, IDLat As Int, IDSym As Int, IDPrb As Int, ID As Int
    ID=0
    If Regex.IsMatch("[\p{IsCyrillic}]*", s)=True Then IDCyr=10000 Else IDCyr=0
    If Regex.IsMatch("[\p{N}]*", s)=True Then IDNum=1000 Else IDNum=0
'    If Regex.IsMatch("[\d]", s)=True Then IDNum=1000 Else IDNum=0
    If Regex.IsMatch("[\p{Po}]*", s)=True Then IDSym=100 Else IDSym=0
    If Regex.IsMatch("[\p{IsLatin}]*", s)=True Then IDLat=10 Else IDLat=0
    If Regex.IsMatch("[\p{Z}*]", s)=True Or Regex.IsMatch("[\p{Zs}]", s)=True Then IDPrb=1 Else IDPrb=0

'    If Regex.IsMatch("[\p{N}]*", s)=True Then IDNum=1001
'    If Regex.IsMatch("(.*\n)*", s)=False Then IDNum=1000

    ID=IDPrb+IDLat+IDSym+IDNum+IDCyr
'    Log("Код строки " & ID)
    Return ID
End Sub
 
Upvote 0

Valeriy Lakhtin

Member
Licensed User
I solve this task!!
It is more convenient to solve the problem by counting the characters natsional language
in Kazakh range you want to print the letters [а-яА-Я] in the Kazakh language
B4X:
Sub CountKaz(s As String) As Int
Dim m As Matcher, n As Int
m = Regex.Matcher("[а-яА-Я]",s)
Do While m.Find
    n=n+1
Loop
Return n
End Sub
in Russian range you want to print the letters [а-яА-Я] in the Russian language
B4X:
Sub CountCyr(s As String) As Int
Dim m As Matcher, n As Int
m = Regex.Matcher("[а-яА-Я]",s)
Do While m.Find
    n=n+1
Loop
Return n
End Sub
Please use [code]code here...[/code] tags when posting code.

Have you tried it? Does it work?
 
Last edited:
Upvote 0
Top