I have a regular expression to return false if special characters are found. I'm trying to modify it to do the same if any single or double quotes are found. This is one time that regexr.com is not helping.
Here is my expression that works for special characters:
^(?=.*?[A-Z]{2})((?!!|@|$|%|\^|&|\*)).)*$
Here is my regular expression for single and double quotes:
^(?=.*?[A-Z]{2})((?!'|").)*$
I even tried escaping them:
^(?=.*?[A-Z]{2})((?!\'|\").)*$
Please help! I've wasted too much time on this and cannot quickly figure it out.
I have a method:
var isValidText = function (val) {
var rx = new RegExp(\^(?=.*?[A-Z]{2})((?!!|@|$|%||^|&||*)).)*$\);
var result = rx.text(val);
return result;
}
Simple input:
We're having a party and my house this weekend. Please bring as many friends as you like; the more the merrier.
This paragraph should be invalid as soon as it finds the single quote in We're.
There's no need for lookaround here, and since you're only matching single characters you can simply use a character set instead of |
.
.*[!@$%^&*'"].*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With