You are viewing limited content. For full access, please sign in.

Question

Question

validate name lookup

asked on September 6, 2017

I can't figure out a regular expression to validate my name entry field.  Our names are entered First Last (Bryan Fatka) and I can get that to work, but my problem is with people who have spaces in their names.  I'm using (\w+)\s*([\w\-]+)\s* as the expression to deal with first and last names that includes hyphens. . .but how do you allow for a "maybe" third name?  For instance "Grace Mary Betony" with two first names or "Jake Di Ackova" with two last names?

The field is a single field, and I'm using a database lookup, but some people start typing a name and then forget to click on the lookup name and just click enter. . .so wanting to make sure they get the full name entered.  Thanks for any help.

0 0

Answer

SELECTED ANSWER
replied on September 6, 2017

Try this: ^(\w*\s){1,2}(\w*)(\-\w*)?$

Allow one or two word/space combinations: (\w*\s){1,2}

Followed by a word: (\w*)

Followed by an optional hyphen/word combination: (\-\w*)?

1 0
replied on September 6, 2017

Thanks, Jason, this worked.  I swear I had tried so many variations but this did the trick.  I appreciate the help.

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.