I have this regex that matches letters and special characters except these
0-9\\d!@#$%^&*()_+-=?>
charcheck:function(val){
var regex = /^[a-zA-Z][^0-9\d!@#$%^&*()_+-=?></\|}{]+$/
return (regex.test(val)) ? true : false;
}
I wanted to add these characters to that list [] but when I do it breaks it. I have even tried ][ but that breaks also.
[
and ]
are special characters in a regular expression. You can use them as literals by escaping them:
/^[a-zA-Z][^0-9\d!@#$%^&*()_+\-=?><\/\\|}{\[\]]+$/
^ ^ as literal
^ - (dash) also needs to be escaped
^ ^ did you intend for these to be literals?
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.