I have a contact form, user supplies name and last name in separate fields. Server side it is used to form From header, like
From: $name $lastname <mailer@mydomain.com>
I have seen a lot of suggestions to use something like A-Za-z, but there are a lot of names containing characters outside latin alphabet. What would be the regex to allow foreign alphabet names, while keeping it secure from email injection?
答案 0 :(得分:1)
Some people have only one name, such as Stack Overflow user sai (https://s.ai/iaq)
Many Hispanic people have multiple surnames, like Juan Pablo Fernández de Calderón García-Iglesias
Some given names are compound words, such as "Billy Bob"
Some surnames are compound words, such as "Vaughn Williams"
Some names are very short, like Po Ng or Malcolm X
Some people have symbols as names, such as The Artist (formerly known as Prince)
Some names include dashes, or apostrophes
Some people have unique names (that won't appear in lists of names), like D'Brickashaw Ferguson
So, the regex would be /.+/
If you're trying to prevent email addresses as names, I would find a good email address validator and make sure a name does not contain an email address