Regular expression in jQuery for Russian letters

I am working on a project targeting the Russian speaking community and I am using form validation for input fields (standard for first name, last name, email, etc.). Everything works fine, but the input field does not recognize Russian letters and considers them to be invalid characters. My current regex line looks like this: / ^ [a-zA-Z '] + $ /
How can I make this shape and understand Russian letters? I have looked at some forums and blogs, but the answers I found did not work for me. Any known workaround for this?

+3


source to share


1 answer


You must use the Unicode range for Cyrillic characters. I checked the table here which gives a range of fragile U+0400 – U+04FF

.

/^[\u0400-\u04FF]*$/.test(''); // true

      



Using Unicode ranges is the most flexible approach as you can choose which characters you want to match. For simpler cases, you can just use a straight range -

, although it won't contain many other Cyrillic characters that are outside this limited range:

/^[-]*$/i.test('');

      

+2


source







All Articles