Html 人员“姓名”字段的合理长度限制是多少?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is a reasonable length limit on person "Name" fields?
提问by EndangeredMassa
I have a simple webform that will allow unauthenticated users to input their information, including name. I gave the name field a limit of 50 characters to coincide with my database table where the field is varchar(50), but then I started to wonder.
我有一个简单的网络表单,允许未经身份验证的用户输入他们的信息,包括姓名。我将名称字段限制为 50 个字符,以与字段为 varchar(50) 的数据库表一致,但随后我开始怀疑。
Is it more appropriate to use something like the Text column type or should I limit the length of the name to something reasonable?
使用类似 Text 列类型的东西更合适还是应该将名称的长度限制为合理的?
I'm using SQL Server 2005, in case that matters in your response.
我正在使用 SQL Server 2005,以防这对您的响应很重要。
EDIT:I did not see this broader questionregarding similar issues.
编辑:我没有看到关于类似问题的更广泛的问题。
回答by Ian Nelson
UK Government Data Standards Cataloguesuggests 35 characters for each of Given Name and Family Name, or 70 characters for a single field to hold the Full Name.
英国政府数据标准目录建议名和姓各 35 个字符,或 70 个字符的单个字段包含全名。
回答by EndangeredMassa
I know I'm late on this one, but I'll add this comment anyway, as others may well come here in the future with similar questions.
我知道我在这个问题上迟到了,但无论如何我都会添加这个评论,因为其他人将来很可能会带着类似的问题来到这里。
Beware of tweaking column sizes dependent on locale. For a start, it sets you up for a maintenance nightmare, leaving aside the fact that people migrate, and take their names with them.
注意根据区域设置调整列大小。首先,它让您陷入维护噩梦,撇开人们迁移的事实,并随身携带他们的名字。
For example, Spanish people with those extra surnames can move to and live in an English-speaking country, and can reasonably expect their full name to be used. Russians have patronymics in addition to their surnames, some African names can be considerably longer than most European names.
例如,拥有这些额外姓氏的西班牙人可以搬到并居住在英语国家,并且可以合理地期望使用他们的全名。俄罗斯人除了姓氏外还有父名,一些非洲人的名字可能比大多数欧洲人的名字长得多。
Go with making each column as wide as you can reasonably do, taking into account the potential row count. I use 40 characters each for first name, other given names and surname and have never found any problems.
考虑到潜在的行数,尽可能使每一列尽可能宽。我的名字、其他名字和姓氏各使用 40 个字符,但从未发现任何问题。
回答by pix0r
I usually go with varchar(255) (255 being the maximum length of a varchar type in MySQL).
我通常使用 varchar(255) (255 是 MySQL 中 varchar 类型的最大长度)。
回答by Thomas Owens
@Ian Nelson: I'm wondering if others see the problem there.
@Ian Nelson:我想知道其他人是否看到了那里的问题。
Let's say you have split fields. That's 70 characters total, 35 for first name and 35 for last name. However, if you have one field, you neglect the space that separates first and last names, short changing you by 1 character. Sure, it's "only" one character, but that could make the difference between someone entering their full name and someone not. Therefore, I would change that suggestion to "35 characters for each of Given Name and Family Name, or 71 characters for a single field to hold the Full Name".
假设您有拆分字段。总共 70 个字符,其中 35 个用于名字,35 个用于姓氏。但是,如果您有一个字段,则会忽略分隔名字和姓氏的空格,将您更改为 1 个字符。当然,它“只有”一个字符,但这可能会导致输入全名的人和不输入全名的人之间的区别。因此,我将该建议更改为“名字和姓氏各为 35 个字符,或单个字段为 71 个字符以保存全名”。
回答by Greg Hurlman
If it's full name in one field, I usually go with 128 - 64/64 for first and last in separate fields - you just never know.
如果它是一个字段中的全名,我通常在不同的字段中使用 128 - 64/64 表示第一个和最后一个 - 你永远不知道。
回答by Steve Cooper
In the UK, there are a few government standards which deal successfully with the bulk of the UK population -- the Passport Office, the Driver & Vehicle Licensing Agency, the Deed Poll office, and the NHS. They use different standards, obviously.
在英国,有一些政府标准可以成功地与大部分英国人口打交道——护照办公室、驾驶员和车辆执照局、契约调查办公室和 NHS。显然,他们使用不同的标准。
Changing your name by Deed Poll allows 300 characters;
通过契约投票更改您的姓名允许 300 个字符;
There is no legal limit on the length of your name, but we impose a limit of 300 characters (including spaces) for your full name.
您的姓名长度没有法律限制,但我们对您的全名施加了 300 个字符(包括空格)的限制。
The NHS uses 70 characters for patient names
PATIENT NAME
Format/length: max an70
患者姓名
格式/长度:最大 an70
The Passport Office allows 30+30 first/lastand Driving Licenses (DVLA) is 30 total.
护照办公室允许第一个/最后一个 30+30 个,驾驶执照 (DVLA) 总共为 30 个。
Note that other organisations will have their own restrictions about what they will show on the documents they produce — for HM Passport Office the limit is 30 characters each for your forename and your surname, and for the DVLA the limit is 30 characters in total for your full name.
请注意,其他组织对他们将在他们制作的文件上显示的内容有自己的限制——对于 HM Passport Office,您的名字和姓氏的限制是每个 30 个字符,而对于 DVLA,您的总限制是 30 个字符。全名。
回答by Wedge
What you're really asking is a related, but substantially different question: how often do I want to truncate names in order to fit them in the database? The answer depends both on the frequency of different lengths of names as well as the maximum lengths chosen. This concern is balanced by the concerns about resources used by the database. Considering how little overhead difference there is between different max lengths for a varchar field I'd generally err on the side of never being forced to truncate a name and make the field as large as I dared.
您真正要问的是一个相关但完全不同的问题:我希望多久截断一次名称以使其适合数据库?答案取决于不同长度名称的频率以及选择的最大长度。这种担忧与对数据库使用的资源的担忧相平衡。考虑到 varchar 字段的不同最大长度之间的开销差异很小,我通常会犯错误,即永远不会被迫截断名称并使该字段尽可能大。
回答by coder1
We use 50.
我们使用 50。
回答by ColinYounger
Note that many cultureshave 'second surnames' often called family names. For example, if you are dealing with Spanish people, they will appreciate having a family name separated from their 'surname'.
请注意,许多文化都有“第二姓氏”,通常称为姓氏。例如,如果您与西班牙人打交道,他们会喜欢将姓氏与他们的“姓氏”分开。
Best bet is to define a data type for the name components, use those for a data type for the surname and tweak depending on locale.
最好的办法是为名称组件定义一个数据类型,将它们用于姓氏的数据类型并根据语言环境进行调整。
回答by Craig
The average first name is about 6 letters. That leaves 43 for a last name. :) Seems like you could probably shorten it if you like.
平均名字大约是 6 个字母。剩下的姓氏为 43。:) 如果您愿意,似乎可以缩短它。
The main question is how many rows do you think you will have? I don't think varchar(50) is going to kill you until you get several million rows.
主要问题是你认为你会有多少行?我不认为 varchar(50) 会杀死你,直到你得到几百万行。