Reputation: 10172
I am using this one to prevent user to type special chars.
String.prototype.isText = function () {return /^[\w\s]*$/.test(this)}
How can i change it to prevent users to type non-english words ? (only apostrophe and &
will be accepted as special char)
Upvotes: 1
Views: 1956
Reputation: 2170
Enforcing English with a regular expression? That's a rather naïve approach, and I'm not sure you'd want to include it on your résumé even if you did manage it. I'm not even sure I'd brag about it at the neighborhood café.
Believe it or not, there are a lot of English words (words that have been completely incorporated into the English lexicon) that are properly spelled with characters that don't match /[a-z]/gi
.
Upvotes: 4
Reputation: 4288
You could try using something like this: http://code.google.com/apis/ajaxlanguage/documentation/#Detect
That is a little bit over complicated if you just want to use regex to detect latin characters, but it will ensure it is actually English.
Upvotes: 1