How can I make a regular expression that would say the following:
FirstName.LastName or FirstName.Letter.LastName
To allow example:
- John.Smith
- John.S.Smith
Not to allow example:
- John Smith
- John
- John.
- John.Smi th
- John.S.D.Smith
Thanks in advance!
Greg
This works; I’ve tested it with all of your examples:
Explanation:
^– anchor to match the start of your string[A-Za-z]+\.– match a letter 1 or more times followed by a period([A-Za-z]\.)?– optionally match a single letter followed by a period[A-Za-z]+– match a letter 1 or more times$– anchor to match the end of your stringHope this helps! For quick reference on regular expressions, see here.