I am trying to create a regular expression to help me validate a particular string that users will be passing into my application. I thought I had it figured out until I found a few test cases that my expression gave a false positive for. Here are the details:
- The first six characters will be letters or spaces.
- The first character must be a letter.
- If the first six characters are not all letters, then the rest of the six are padded with spaces.
Here are some examples of valid strings:
So I quickly whipped up the below expression to validate these strings:
The problem is this can create false positives because I am not properly meeting requirement number 3. Here are some strings that cause false positives:
I'm not the best at regular expressions so I am kind of stumped as to how to proceed. How do I check the first six characters so that they are letters until a space is found and then it is padded until it reaches 6 characters. Thank you in advance for your help.