RegEx for parsing peoples names?

  • Thread starter Thread starter Ben Fidge
  • Start date Start date
B

Ben Fidge

Hi

I'm trying (and failing) to create and regular expression for parsing
peoples names. I simply want to make sure that a firstname and surname, at
least, can be extracted.

For example, "Ben Fidge" would pass, however, "Ben", "Fidge", "Ben-Fidge"
and BenFidge" wouldn't.

I want to use a RegularExpressionValidator on an ASP.NET page to ensure that
people provide first and surnames in a single text box. Unfortunately, I
can't provide two text boxes for legacy reasons.

TIA

Ben
 
Ben,

Why not just call the Split method on the string, delimiting by a space
character? If the array that is returned is one element (or none), then you
know it is invalid.

I mean, do you really need a regular expression to do this? It seems
like overkill for something so simple. If anything, you can encapsulate
this logic in a method, and swap it out with a regular expression as your
needs get more complex.

Hope this helps.
 
Back
Top