there are some similar questions out there, but none that are quite the same or that have an answer that works for me.
I need a javascript function which validates whether a text field contains all valid latin characters, so no cryllic or Chinese, just latin; specifically:
Basic Latin (excluding the C0 control characters), Latin-1 (excluding the C1 control characters), Latin Extended A, Latin Extended B and Latin Extended Additional. This set corresponds to Unicode code points U+0020 to U+007E, U+00A0 to U+024F and U+IE00 to U+IEFF
Some of the answers out there seem to check the first character in the text field but miss out others, so these are no good.
This is what I have tried so far (this doesn't work!):
var value = 'abcdef' // from text field
var re = '\u0000-\u007F|\u0100-\u017F|\u0180-\u024F|\u1E00-\u1EFF|\u0080-\u00FF'; // latin regexp string
// var re = '\\w+/'; // alternative
if (new RegExp(re).test(value)) {
result = false;
}
The following sort of works but only for the first character:
//var re = '\u0000-\u007F|\u0100-\u017F|\u0180-\u024F|\u1E00-\u1EFF|\u0080-\u00FF'; // latin regexp string
// couldn't get the above to work so using the following:
var re = '\\w+';
if (!value.match(re)) {
message = 'Please enter valid latin characters only';
$focusField = $this;
}
What is the right way to do this?
I really need code, rather than an explaination, but both would be better.
Thanks