0

I'm having big trouble trying to find or come up with a regular expression pattern for two or more words. The context: I have a form where I'm asking for name, users are supposed to type first and last name and a parser divides it as I want. The problem that I found is that if the parser fails or what they input is wrong there's no way the know it's the name. I'm using patterns on the rest of the fields so using one in the name is the best idea design-wise.

I don't know much about Regular Expressions so could somebody tell me if there's a way? It has to be two or more words.

  • How do you define "word"? – user202729 Jan 16 '18 at 09:53
  • [Potential duplicate](https://stackoverflow.com/questions/36817529) – user202729 Jan 16 '18 at 09:54
  • 2
    If you really require two names, use two separate fields. If you only want one name, use one field and DO NOT split it. You DO NOT know how to split an arbitrary name into first/last name, so don't try it. FYI: http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ – ThiefMaster Jan 16 '18 at 10:00
  • I've already read that article and I do know how to split a name in fact it's working as intended. I know parsing names is not optimal but that's what I'm asked to do, I'm just trying to optimize it. So the discussion is not about whether or not to do it but how to do it best. Words are being slip and therefore defined by spaces, so if I write A B-C, one word is A and the other B-C. – Marc Castellanos Jan 16 '18 at 14:07

0 Answers0