Restrict data entry to custom format

crosb

New Member
Joined
Feb 1, 2018
Messages
2
Hi,

I'm trying to figure out a formula for data validation to restrict entries in a cell to a certain format... it can be a text string, doesn't have to be a date value or anything, but the format has to be:

YYYY-ABC123-123

where

yyyy is a four digit year
the dash is present
abc are any letters
123 are three numbers
the second dash is present
123 are three more numbers

Is there a way to enforce this at all? and show the ****-******-*** style to a user when they click on the cell so they know what style they have to follow?

Thanks so much in advance!!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
add this as validation rule, if your cell is in A1

Code:
=IF(LEN(A1)=15,AND(ISNUMBER(--LEFT(A1,4)),MID(A1,5,1)="-",SUM(--ISERROR(--MID(A1,ROW($6:$8),1)))=3,ISNUMBER(--MID(A1,9,3)),MID(A1,12,1)="-",ISNUMBER(--RIGHT(A1,3))),FALSE)
 
Last edited:
Upvote 0
That is excellent. Thank you so much!!!

add this as validation rule, if your cell is in A1

Code:
=IF(LEN(A1)=15,AND(ISNUMBER(--LEFT(A1,4)),MID(A1,5,1)="-",SUM(--ISERROR(--MID(A1,ROW($6:$8),1)))=3,ISNUMBER(--MID(A1,9,3)),MID(A1,12,1)="-",ISNUMBER(--RIGHT(A1,3))),FALSE)
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top