Limit text length in Excel for ID and passport numbers

You can use Data Validation to stop typo’s when people are entering information. So perhaps you want to limit text length in Excel for ID and passport numbers. If it is an ID number then exactly 13 characters must be entered, but if it is another document type then you can allow more or less.

As shown below in column A we have a dropdown that says whether the document is an ID or other document. This column drives column C and D which (using an IF function) creates the minimum and maximum number of characters allowed for that type.

Then we just need to highlight the relevant cells in column B, and

  • Click DATA and DATA VALIDATION
  • Choose to allow Text Length
  • Choose Between
  • in the Minimum section link it to cell C8
  • in the Maximum section link it to cell D8
  • Press OK.

Limit text length in Excel for ID and passport numbers

Now when it says ID in column A (e.g. cell A10), then if we enter the wrong number in B10 it will stop the user with an error message. So below we entered a passport number in B10 when it should have been an ID number of 13 characters. We get a custom error message (you can do this in Data Validation as well!)

Limit text length in Excel for ID and passport numbers

This is a good way to stop typos at the source instead of fixing them only later when they are found.