3

I've been working on a project oriented on Russian-speaking community, and I'm using form validation for input fields (standard ones for name, surname, email, etc.). Everything works just fine, but the input field does not recognise Russian letters and considers them as not-allowed symbols. My current regexp line looks like this: /^[a-zA-Z ']+$/
How could I make this form also understand Russian letters? I've looked through some forums and blogs but the answers that I've found did not work for me. Any known workaround for this?

Brandon Buck
  • 7,177
  • 2
  • 30
  • 51
Balabeque
  • 307
  • 3
  • 16

1 Answers1

2

You should use Unicode range for Cyrilic characters. I checked the table here which gives range of chracters U+0400 – U+04FF.

/^[\u0400-\u04FF]*$/.test('проверка'); // true

Using unicode ranges is the most flexible approach since you can select what characters you want to match. For simpler cases you can just use direct а-я range, although it will leave out many other cyrilic characters that are outside of this limited range:

/^[а-я]*$/i.test('Проверка');
dfsq
  • 191,768
  • 25
  • 236
  • 258