So i need to apply some regex that checks if the text entered is alphanumeric with possible special characters, such as apostrophes, but should not accept special characters without alphanumeric characters.
For example:
- "Someone's thing" returns 5 results
- "(')" returns "invalid"
I've currently got:
var regexItem = new Regex("^[a-zA-Z0-9 ]*$"); if (!regexItem.IsMatch(searchTerm)) { return null; } That works for alphanumeric values and blocks inputs with just special characters but if there is an apostrophe in the search term, it will return null.
Is this possible?
UPDATE:
new code looks like this.
var regexItem = new Regex("^(?=[^a-zA-Z0-9]*[A-Za-z0-9])[a-zA-Z0-9 '()]* $"); if (!regexItem.IsMatch(searchTerm)) { return null; }
^(?=[^a-zA-Z0-9]*[A-Za-z0-9])[a-zA-Z0-9 '"()]*$regex101.com/r/rGaTEl/1