I'm looking for a regular expression to use in Swift to validate the full name. I'm looking for a regex that has a minimum of 2 and a maximum of 100 characters - Accept Accents, dashes (-) and apostrophes (') and no other special character - Upper and lower case letters and no numbers. - It must not start with a blank space and cannot have more than 1 blank space between the names.
I was using this - "(?mi)^[A-Za-zÀ-ú](??(:..*\?\/\ ){2})(?:(.?.* ){10})(..,*\.[az])[A-Za-zÀ-ú. '-]{5,99}[A-Za-zÀ-ú]$"
but is accepting more than one space and some names that I shouldn't
link https://regex101.com/r/493eLF/12
Thank you in advance for any help.
You might use a repeating group that starts with a single space followed by repeating 1+ times the listed characters in the character class.
To verify the string length, you could use a positive lookahead at the start of the string.
If there should be no trailing spaces allowed, you can omit the *
at the end right before the $
If the single uppercase chars are also allowed, you can change the quantifier for the first [A-Za-zÀ-ú.'-]+
to *
^(?=.{2,100}$)[A-Za-zÀ-ú][A-Za-zÀ-ú.'-]+(?: [A-Za-zÀ-ú.'-]+)* *$
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.