0

I have a Google form where I am asking for the user to include their "full name" to keep the form short and sweet (without two inputs for first name/last name). You are able to validate answers in Google Forms using regular expressions, but I'm not sure where to start.

I want at minimum two words in the input, each with at least 2 characters, and I don't want to block any special characters (so that people with names like O'Leary can still write it). Basically, I just want to make sure there are two words included in a field, each with at least 2 letters.

I have no experience with regex or the patterns so any help is appreciated!

becca
  • 720
  • 1
  • 9
  • 24
  • Possible duplicate of [What is a word boundary in regexes?](https://stackoverflow.com/questions/1324676/what-is-a-word-boundary-in-regexes) – Rubén Jan 16 '19 at 04:15

1 Answers1

2

I builded this regular expresion to accept full names from a lot of countries:

^([a-zA-Z\-ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïòóôõöùúûüýÿ']{2,75} ?){2,5}$

You can test it on regex101.com. This site also helps you understand this regex with explanations on the top right.

Hope it helps.

  • I thought this solved it but after some extra testing I noticed that I could just write "Becca" and it would accept that as a first and last name, as long as there was 3+ characters. Is there any way to specify there has to be two different words, each with at least 2 characters? – becca Jan 16 '19 at 20:22
  • 1
    It is due to the `?` after the space. If you want to match only if there is 2 words you can use this regular expression: `[a-zA-Z\-ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïòóôõöùúûüýÿ']{2,75} [a-zA-Z\-ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïòóôõöùúûüýÿ']{2,75}`. If you want to accept more words after the two first you can use this one: `^[a-zA-Z\-ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïòóôõöùúûüýÿ']{2,75} ([a-zA-Z\-ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïòóôõöùúûüýÿ']{2,75} ?){1,2}$` and change the number `2` with the number you want. – Corentin MERCIER Jan 16 '19 at 22:31