Regular expressions with cyrillic?

I am currently writing some validation that will validate the data entered. I use regular expressions for this while working with C #.

Password = @"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,18})$" Validate Alpha Numeric = [^a-zA-Z0-9ñÑáÁéÉíÍóÓúÚüÜ¡¿{0}] 

The above work is excellent in the Latin alphabet, but how can I expand it to work with the Cyrillic alphabet?

+4
source share
3 answers

The basic approach to spanning ranges of characters using regular expressions is to build an expression of the form [A-Za-z] , where A is the first letter of the range and Z is the last letter of the range.

The problem is that there is no such thing as “The” Cyrillic alphabet: the alphabet is slightly different depending on the language. If you want to use the Russian version of the Cyrillic alphabet, use [--] . You would use a different range, say, for Serbian, because the last letter in their Cyrillic alphabet is , and not

Another approach is to list all the characters one by one. Just find the authoritative link for the alphabet that you want to put in the regular expression and put all the characters in it in square brackets:

 [] 
+7
source

You can use character classes if you need to allow characters of a certain language or a certain type:

 @"\p{IsCyrillic}+" // Cyrillic letters @"[\p{Ll}\p{Lt}]+" // any upper/lower case letters in any language 

In your case, there may be enough "no spaces": @"[^\s]+" or maybe "a word character (which includes numbers and underscores) - @"\w+" .

+6
source
 Password = @"(?!^[0-9]*$)(?!^[--]*$)^([--0-9]{6,18})$" Validate Alpha Numeric = [^--0-9ñÑáÁéÉíÍóÓúÚüÜ¡¿{0}] 
+1
source

All Articles