Apply a Data Validation rule to the cell. Select 'Text Length' under Allow, select 'Less than or equal to' under Data and put 18 in 'maximum'. Select the 'Ignore Blanks' checkmark depending upon whether you want a blank to count as one of the 18 characters. Set the other controls regarding messages etc. This will take care of the 18 criteria.
To restrict entry to specific characters only, I suspect you will need a VBA solution, something not in my bailiwick.