arashid
arashid

Reputation: 29

regex for name verification

I am trying to build a regex that fulfills these requirements, but I am not sure how to do it. I tried with:

[A-Z][a-z]+[,][ ][A-z][a-z]+($|[[ ]{0,1}[A-Z][.]]{0,1})

but it's not doing what I want. I need some help.

Requirements

Last, First M.

Last - must begin with a capital letter and be followed by one more lower case letters.

First - must begin with a capital letter and be followed by one or more lower case letters.

M. - must be a single capital letter followed by a period (.). This part (including the preceding space) is optional.

Examples of valid accepted strings are:

Invalid examples are:

Upvotes: 0

Views: 75

Answers (1)

Laurent H.
Laurent H.

Reputation: 6526

I suggest you the following regex to be compliant with your requirements:

[A-Z][a-z]+, [A-Z][a-z]+( [A-Z]\.)?

Upvotes: 1

Related Questions