The ? indicates exactly one character.
Therefore the expression:
Like "????"
means it must be 4 characters.
You asked for only 13 characters, or only 8 characters.
So the expression is crafted to permit those 2 options only.
Not 6 characters, not 14, only 8 or 13 characters.
The expression:
[a-z]
permits alpha characters only.
The expression:
[!a-z]
permits non-alpha characters only.
The expression:
Like "*[!a-z]*"
matches a non-alpha character in any position in the string.
The expression:
NOT LIKE "*[!a-z]*"
means it is not allowed to have any non-alpha character anywhere in the
string.
You want to permit digits as well as letters, so the expression you need is:
NOT LIKE "*[!((a-z) or (0-9))]*"
(That's omitting the requirement that the field be exactly 8 or exactly 13
characters, as I am not clear about what you wanted there.)
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
The rule will be something like this:
(Is Null) OR (((LIKE "????????") OR (LIKE "?????????????"))
AND NOT (Like "*[!a-z]*") AND NOT LIKE "*[!0-9]*"))
That's untested, but hopefully enough to get you on the track.
Hello,
I'm looking for a data validation rule that would preclude users from
entering anything into a table except:
A 13 character string that can only contain numbers or letters.
or
An 8 character string that can only contain numbers or letters.
Thanks,
alex- Hide quoted text -
- Show quoted text -
Thanks Allen for the help.
I think I understand "?", which will limit the string to the same
number of characters (in my example 13 or 9 characters).
I also do not want anyone to enter a character except a letter or
number, e.g., no special characters, which I'm assuming (Like "*[!a-
z]*") AND NOT LIKE "*[!0-9]*")) should do.
I copied the above validation, but it doesn't seem to work...it allows
13 characters of any type...it also strangely does not allow any
string above or below 13 characters, even though we stated or (like
"?????????")
- Show quoted text -