Restrict Entering Special Characters in Google Sheets (Data Validation)

Published on

We can use the Data menu Data validation to ensure the quality and accuracy of values entered in Google Sheets. This post describes how to restrict people from entering special characters in a selected cell range using Data validation in Google Sheets.

We will use the Regexmatch function to code a custom formula to deny the entry of any special characters in the selected range in Google Sheets.

We have multiple Data validation rules coded for your specific purposes. You can allow only specific special characters such as commas, periods, and question marks or deny all of them outright.

This walkthrough may help you modify my formula to suit your data accuracy requirements.

Purpose of Restrict Entering Special Characters in Google Sheets

In your daily digital life, so many times, you may have come across the term special characters. They are non-alphanumeric characters.

Unlike alphabetic and numeric (alphanumeric) characters, some special characters may have multiple uses in functions like Query, Regexmatch, Regexreplace, and Regexextract.

To prevent problems, you may want to use a backslash ( \ ) to escape some special characters when using them in the said functions.

For example, to match “DRG152 (Rev 2)” you can use =regexmatch(D8,"DRG152 \(Rev 2\)"). In this, I’ve escaped the open and close parenthesis using a \.

For the smooth functioning of the above functions, sometimes you may want users not to enter special characters in cells.

Let’s see how to restrict users from entering special characters in a cell or cell range by setting up a Data validation rule in Google Sheets.

Setting Up a Data Validation Rule in Google Sheets

To set up Data validation, please follow the below steps.

Select the cell or cell range where you want to apply the Data validation rule. For example, select A1:A by clicking on column label A.

Go to the menu Data > Data Validation > Add rule > Criteria > Custom formula is.

As per our example, the settings up to this point will be as follows.

Restrict Entering Special Characters: Data Validation Setting

We will insert a custom formula to restrict entering special characters in the Data validation formula field under “Custom formula is.”

Regexmatch in Data Validation to Restrict Users from Entering Special Characters

Here is our custom Regexmatch formula to enter into the above formula field in Data validation.

=REGEXMATCH(A1&"","^[a-zA-Z0-9]*$")

Please note one thing. We want to restrict the entry of all special characters in column A. But, in the formula, we only require to specify the topmost cell in the range, here A1.

The above formula can restrict users from entering all special characters in the range A1:A in Google Sheets.

In other words, the formula above would only allow people to enter upper-case and lower-case letters and numbers.

Does the above rule allow space characters?

Nope! In that case, modify it as below.

=REGEXMATCH(A1&"","^[a-zA-Z0-9\s]*$")

I want to deny people from entering only specific special characters in Google Sheets. Ho to do that?

See the below formula.

=NOT(REGEXMATCH(A1&"","[\&\$\%\#\@\!]"))

It will only restrict the characters given within the square brackets, i.e., &,$,%,#,@,!.

That’s all. Thanks for the stay. Enjoy!

Resources:

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

How to Extract Numbers from Text in Excel with Regex

You can use the REGEXEXTRACT or REGEXREPLACE functions to easily extract numbers from text...

Using OFFSET and MATCH Together in Google Sheets: Advanced Tips

One powerful and flexible way to look up values is by combining the OFFSET...

How to Use OFFSET and XMATCH Functions Together in Excel

We often use the OFFSET and XMATCH functions together to match a value in...

How to Calculate Maximum Drawdown in Excel and Google Sheets

You can use the following dynamic array formula to calculate maximum drawdown (MDD) in...

More like this

Using OFFSET and MATCH Together in Google Sheets: Advanced Tips

One powerful and flexible way to look up values is by combining the OFFSET...

Running Count with Structured References in Google Sheets

Running a count with structured references is achievable in Google Sheets tables using the...

Running Total with Structured Table References in Google Sheets

You can use two types of formulas to create a running total with structured...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.