简体   繁体   中英

Javascript regexp lets undesirable characters

I'm using a regExp in my project but some how I'm getting some undesirable characters

my RegExp looks like this:

new RegExp("[א-ת,A-z,',','(',')','.','-',''']");

which supposed to avoid characters like \\ or []

but let my use one and more from (,),-,alphabets etc.

Unfortunately it doesnt happen

Which pattren includes both desirable and undesirable characters??

thanks for your help

Well your regular expression just says to match one "good" character (and incorrectly at that).

I think something closer to this would be what you want, though I'm not sure about the higher-page UTC characters:

var regexp = /^[א-תA-Za-z,()\-']*$/;

If the alefbet part doesn't work (it looks backwards to me, but I guess that's kind of a conundrum :-), try:

var regexp = /^[\u05DA-\05EAA-Za-z,()\-']*$/;

Might be good to tack an "i" (ignore case) modifier on the end too:

var regexp = /^[\u05DA-\05EAA-Za-z,()\-']*$/i;

This also does not handler the various diacritical marks; I don't know if you need those matched or not.

First of all, you don't need all those single quotes and commas. Second, you want A-Za-z , not. Az . The latter includes ASCII characters between "Z" and "a".

var re = new RegExp("[א-תA-Za-z,()\.'\s-]");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM