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?
Asked
Active
Viewed 2,295 times
3

Brandon Buck
- 7,177
- 2
- 30
- 51

Balabeque
- 307
- 3
- 16
-
1In some languages cyrillic chars can be matched by `\p{Cyrillic}`. – Andrew Dunai Dec 11 '14 at 22:23
-
Also, try this one: http://stackoverflow.com/questions/18471159/regular-expression-with-the-cyrillic-alphabet – Andrew Dunai Dec 11 '14 at 22:23
-
I think will help you http://stackoverflow.com/a/18471465/4332533 – Freez Dec 11 '14 at 22:25
-
Are you coding your own validator? – Banzay Dec 11 '14 at 22:26
-
Nope @Banzay, it's just a nice plugin specially written for Bootstrap 3 – Balabeque Dec 11 '14 at 22:59
-
1so what a trouble?! If it's a bootstrapValidator, then I just wrote /^['a-zA-Zа-яА-Я ']+$/ – Banzay Dec 11 '14 at 23:21
1 Answers
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