Javascript regex to find single or double quote not working

I have a regex to return false if special characters are found. I am trying to modify it to do the same if any single or double quotes are found. This is one time when regexr.com does not help.

Here is my expression that works for special characters:

^(?=.*?[AZ]{2})((?!!|@|$|%|\^|&|\*)).)*$ 

Here is my regex for single and double quotes:

 ^(?=.*?[AZ]{2})((?!'|").)*$ 

I even tried to run away from them:

 ^(?=.*?[AZ]{2})((?!\'|\").)*$ 

Please, help! I have spent too much time on this and cannot quickly figure it out.

I have a method:

 var isValidText = function (val) { var rx = new RegExp(\^(?=.*?[AZ]{2})((?!!|@|$|%||^|&||*)).)*$\); var result = rx.text(val); return result; } 

Simple input:

We have a party and my house this weekend. Please bring as many friends as you like; the more fun.

This paragraph should be invalidated as soon as it finds a single quotation mark in "We".

+7
javascript regex
source share
1 answer

There is no need to search, and since you are using only individual characters, you can simply use a character set instead of | .

.*[ !@ $%^&*'"].*

+6
source share

All Articles