This article will show you some examples of how to validate text data input in excel cells.
- The first example shows you how to restrict the input text length.
- The second example shows you how to allow input text only in the excel cell.
- The third example shows you how to allow input text that starts or ends with specified text.
- The fourth example shows you how to allow input text that contains specified text.
1. How To Restrict Input Text Length In Excel.
- Select cell A1 in the excel worksheet.
- Click the Data tab —> Data Tools group —> Data Validation menu item to open the Data Validation dialog window.
- Click the Settings tab, and select Text length from the Allow drop-down list.
- Select the item greater than from the Data drop-down list.
- Input number 6 in the Minimum input text box.
- Click the Input Message tab, then input the text Input Text in the Title text box, and input the text The text length should be greater than 6. in the Input message text area.
- Click the Error Alert tab, and select Stop from the Style drop-down list.
- Input the text Text length is not valid in the Title text box.
- Input the text The input text length should be greater than 6. in the Error message text area.
- Click the OK button to create the data validation rule.
- Select cell A1 and drag the small green square on the bottom right corner of cell A1 to apply the text data validation rule to other cells.
- You can select the other cells and click the Data tab —> Data Tools group —> Data Validation item to verify that the data validation rule has been applied to the cells.
- Now when you select the cell that applies the above validation rule, it will show a yellow tip message dialog beside the cell.
- If you input a text that length is not greater than 6 and press the OK button, it will show an alert dialog window.
2. How To Allow Input Text Only In Excel Cells.
- Open the excel Data Validation dialog window.
- Click the Settings tab.
- Select Custom from the Allow drop-down list.
- Input the formula =ISTEXT(A1) in the Formula text box.
- Input the title and message in the Input Message and Error Alert tab text fields.
- Then when the user inputs a none text value, it will alert a dialog window.
3. How To Allow Input Text That Start/End With Specific Characters.
- If you only allow users to input text beginning or ending with a specific string, you can use the COUNTIF function.
- Select the target cells in the excel worksheet, then click the Data tab —> Data Tools group —> Data Validation item, it will open the Data Validation dialog window.
- Select the item Custom from the Allow drop-down list in the Settings tab.
- In the Formula text box, input the formula =COUNTIF(A1,”PYTHON*”) + COUNTIF(A1,”*JAVA”) in it.
- The above formula will only allow the cell text to start with python or end with java ( case insensitive ).
- The * character after PYTHON or before JAVA can match 0 or more other characters.
- The + character between the above 2 COUNTIF functions means OR relationship, which means either python-1 or ABC-java is the valid text by this rule.
- The COUNTIF function is case insensitive, if you want to create a case-sensitive validation formula, you can combine LEFT, RIGHT, and EXACT functions together like below.
- Combine LEFT and EXACT to create a case-sensitive start-with validation formula like this =EXACT(LEFT(A1,6), “PYTHON”).
- Combine RIGHT and EXACT to create a case-sensitive end-with validation formula like this =EXACT(RIGHT(A1,4), “JAVA”).
- Create a formula that allows either start with PYTHON ( case-sensitive ) or end with JAVA ( case-sensitive ), you can use the formula =EXACT(LEFT(A1,6), “PYTHON”) + EXACT(RIGHT(A1,4), “JAVA”).
4. How To Allow Input Text That Contains Specific String Only.
- Sometimes, you may only allow the user to input text that contains the specified string in an excel cell, then you can combine the excel functions ISNUMBER, SEARCH, and FIND.
- The function SEARCH(text, cell) will search the provided text in the cell value, if locate the text in the cell value then return a number to represent the text position in the cell. The SEARCH function is case-insensitive.
- The function FIND(text, cell) is similar to the function SEARCH(text, cell), but it is case-sensitive.
- The function ISNUMBER checks whether the returned value by the function SEARCH or FIND is a numeric value or not, if they return a number then that means the specified text is found in the cell.
- You can open the Data Validation dialog window.
- Click the Settings tab, and select the item Custom from the Allow list.
- Input the formula =ISNUMBER(SEARCH(“python”, A1)) + ISNUMBER(FIND(“JAVA”, A1)) in the Formula text box.
- Now when you enter the text hello-python in cell A1, it is allowed, but when you input text hello-java in cell A1, it will prompt an error dialog because you should use JAVA to replace java.