unicode - 使用 unicode 输入显示 "input too long"错误的最佳方法?

标签 unicode error-handling

当单个字符不等于一个字节时,是否有人有好的建议来向用户显示“超出最大长度”错误?

我无言以对,但我找到了a quote that's more eloquent :

If the buffer runs over by three bytes, what do you tell the user? Three bytes could be one, two, or three characters that the user needs to trim. Depending on which characters they trim, the result might still be too long. And recall that the user's perception of "a character" is probably closer to a grapheme or grapheme cluster than to a character. So they might delete too many characters without realizing it. Finally, if the buffer limit is small (like 10 or 20), some languages like Chinese will be severely restricted on the number of characters permitted.

我面临的几个限制是,它是一个表单驱动的网站,并且底层数据库列的大小无法更改(引用页面建议使用 40 字节缓冲区并强制执行 10 个字符的限制)。

最佳答案

解决此问题的我最喜欢的方法是突出显示超过最大长度的输入部分。这提供了一个视觉提示,表明哪个部分使其“太长”,而无需了解它有多少字节或字符的细节。

如果你可以使用Javascript(例如,如果你不需要满足508标准),我也喜欢监视字段的长度并在太长时提醒用户(同时仍然进行服务器端验证,当然)。

如果您不想在输入字段中使用复杂的 CSS,您可以在字段下方重现错误的输入并在那里突出显示它。

关于unicode - 使用 unicode 输入显示 "input too long"错误的最佳方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/669576/

相关文章:

unicode - 使用 Unicode 报告编译器错误消息行/列号

string - 如何在 Dart 中反转包含代理对的字符串?

java - 如何将 StAX 解析器与元音变音 (äÜÖ) 一起使用?

python - 在500 HTTP服务器错误后重试,从文件中使用的最后一行继续

JavaScript:是否可以获取未定义函数的尝试名称?

c++ - C++ 标准是否要求对 wchar_t 进行编码?

C编程: How to program for Unicode?

javascript - 当您无法控制时如何规避同源策略错误

php - 如何获取PHP中的SQL Server触发器错误?

sockets - 如何找到已经在使用的地址?