Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to validate initials

Tags:

regex

I'm looking for a regex to validate initials. The only format I want it to allow is:

(a capital followed by a period), and that one or more times

Valid examples:

A.
A.B.
A.B.C.

Invalid examples:

a.
a
A
A B
A B C
AB
ABC

Using The Regulator and some websites I have found the following regex, but it only allows exactly one upper (or lower!) case character followed by a period:

^[A-Z][/.]$

Basically I only need to know how to force upper case characters, and how I can repeat the validation to allow more the one occurence of an upper case character followed by a period.

like image 584
George Avatar asked Jun 16 '10 09:06

George


1 Answers

You almost has it right: + says "one or more occurenses" and it's \., not /.

Wrapping it in () denotes that it's a group.

^([A-Z]\.)+$
like image 182
simendsjo Avatar answered Sep 25 '22 14:09

simendsjo