Valid names
This challenge looks like a fun experiment in building a simple rules-based validator.
Definitions:
- A name is a sequence of terms separated by a space. It must have at least 2 terms. The last term must be a word.
- A term is either an initial or a word.
- An initial is a single capital letter followed by a period.
- A word is a capital letter followed by one or more letters (upper or lower case).
Write a function that checks whether a string is a valid name.
Examples
Valid names:
- George R. R. Martin
- Abraham Lincoln
- J. R. Bob Dobbs
- H. G. Wells
Invalid names:
- J R Tolkien (no periods)
- J. F. K. (must end in word)
- Franklin (must have at least two terms)
Thanks to this site for the challenge idea where it is considered Expert in JavaScript. The problem has been modified from the original.
Please submit your solutions as comments on this gist.
Spec really is shining in this one wow