Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Spreadsheets: - Validating cell contains only alphanumeric and underscore

In Google Spreadsheets, how do I use a custom formula (with re2 regular expression) to only allow alphanumeric and underscore characters in cell content?

like image 490
Orion Avatar asked Oct 21 '25 12:10

Orion


1 Answers

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.

like image 146
1owk3y Avatar answered Oct 23 '25 08:10

1owk3y



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!