In Google Spreadsheets, how do I use a custom formula (with re2 regular expression) to only allow alphanumeric and underscore characters in cell content?
I needed a Validation which would detect this also. Here's my working solution.
=IF(REGEXMATCH(A1, "[^A-Za-z0-9_-]+"), FALSE, TRUE)
This Regex validation [^A-Za-z0-9_-]+ returns TRUE if anything is present in the string EXCEPT for letters, numbers, underscores and dashes (The ^ asserts a 'negated set')
Then we simply flip the boolean logic (using 'IF...FALSE,TRUE'). This results rejection of illegal characters.
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