I am checking a field if it is Latin Characters or not.
var foreignCharacters = $("#foreign_characters").val();
var rlatins = /[\u0000-\u007f]/;
if (rlatins.test(foreignCharacters)) {
alert("This is Latin Characters");
} else {
alert("This is non-latin Characters");
}
This works well, but I would like to change it so when I enter any non-latin characters, such as chinese characters, along with a space(which is within that range I am using currently) it will still say it is non-latin characters.
How can I change the regular expression I have to do that?
An alternative to making your own regex with code point ranges is to use the xregexp library
Some examples from the documentation:
XRegExp('^\\p{Hiragana}+$').test('ひらがな'); // -> true
XRegExp('^[\\p{Latin}\\p{Common}]+$').test('Über Café.'); // -> true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With