2

I want to do data validation using excel on a column of the type:

year followed by "-" followed by another year.

example 2010-2011 Can this be done using excel formulas? Can we use regex for this?

1 Answer 1

3

Try this formula (assumes A1 contains value to validate):

=AND(LEN(A1)=9, MID(A1,5,1)="-", ISNUMBER(LEFT(A1,4)+0),ISNUMBER(RIGHT(A1,4)+0))

This will correctly identify the following examples:

  1. 2010-2011 (valid)
  2. abc-2011 (invalid)
  3. 2010-abc-2011 (invalid)
Sign up to request clarification or add additional context in comments.

3 Comments

The +0 trick is nice. I had a similar idea but was thrown by the fact that Left (and Mid) makes the result a string. I was looking at cumbersome expressions like NOT(ISERROR(VALUE(LEFT(... etc.
Can i apply it to an entire column instead of one cell?
@rrgirish yes - copy the formula down the entire column

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.