views:

63

answers:

3

Hi,

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)

thanks so much

+1  A: 

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.

Andrew M
A: 

Try to use this regexp:

/^[a-z\s'&]*$/i
Nakilon
Juan Mendes
Oops, true, I forgot `/i` for capital letters.
Nakilon
@Juan you are right
Ahmet vardar
+4  A: 

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.

Stan Rogers