I have some string and I need to check if this string:
a) consists of 3 words b) contains ONLY cyrillic symbols and spaces
My code:
var isValid;
isValid = function(s) {
return s && s.split(" ").length === 3 && /[а-яА-Я ]/.test(s);
};
But this code doesn't work, because isValid('a b c') returns 'true'. What is my mistake? Thanks in advance!
I have some string and I need to check if this string:
a) consists of 3 words b) contains ONLY cyrillic symbols and spaces
My code:
var isValid;
isValid = function(s) {
return s && s.split(" ").length === 3 && /[а-яА-Я ]/.test(s);
};
But this code doesn't work, because isValid('a b c') returns 'true'. What is my mistake? Thanks in advance!
Share asked Sep 22, 2015 at 6:18 malcoaurimalcoauri 12.2k28 gold badges88 silver badges141 bronze badges 1- Try this link ? – huwence Commented Sep 22, 2015 at 6:29
1 Answer
Reset to default 7Try this:
var isValid = function(s) {
return s && s.split(" ").length === 3 && /^[\u0400-\u04FF ]+$/.test(s);
};