Reputation: 194
A field needs validation to only be able to contain (A|B|C|D|E|F|G|H)
or blank
Is anybody sure on a regex for this validation?
Currently have this: ^[A-Ha-h]{1}$
Upvotes: 2
Views: 263
Reputation: 73452
Use this pattern
@"^(?i)[a-h\s]$"
(?i) - Ignore case
a-h - A-H, a-h
\s - matches white space
Upvotes: 2
Reputation: 149020
If by 'blank space' you mean a literal space character, try this:
^[A-Ha-h ]$
Or use the the RegexOptions.IgnoreCase
and simplify this to
^[A-H ]$
On the other hand, if by 'blank space' you mean an empty string, try this:
^[A-Ha-h]?$
Or with RegexOptions.IgnoreCase
:
^[A-H]?$
Upvotes: 2
Reputation: 19423
Just a simple change:
^[A-Ha-h]?$
^
This makes it optional to input the character, thus allowing you to input blank.
Upvotes: 6