I have a requirement to validate a persons Initials against the following rules:
This is as far as I have got:
^[[:alpha:]]([[:alpha:]]|([[:blank:]-])[[:alpha:]])*([[:blank:]-][:alpha:]|[:alpha:])?$
It does 1 and 2 (and allows for spaces and hyphens) but does not ensure that alpha characters are separated by either a space or hyphen i.e AD evaluates to true.
Thanks for any help. I am pretty new to Regular Expressions so any help is appreciated.
^([A-Z][ -])*[A-Z]$
- start
- -- any number of times
----- a capital letter
---- followed by exactly one separator (space or hyphen)
----- followed by a final (and possibly initial) capital letter