jquery validate:如何验证中文和英文字符的用户名最小长度不同?
我正在使用 jQuery.validate 插件来验证用户注册表单的输入。
我已经完成了简单的案例(确保用户名至少有 6 个字符)
$('#new_user').validate({
rules: {
"user[name]": {
required: true,
minlength: 6,
remote:"/check_name"
}, ...
我想在上述规则中添加一个警告是允许至少 2 个中文字符或 6 个常规字符通过长度测试。 (这对于中国用户来说被认为是很好的可用性,他们中的许多人在现实生活中都有2-3个汉字名字)
例如,我希望以下名字能够通过长度测试:
“张三” “Michael”
及以下名字失败(由于太短) “张” “Mike”
您如何编写自定义 JavaScript 函数来检查这些条件?
I'm using the jQuery.validate plugin to validate inputs for my user registration form.
I've got the simple case working(make sure user name is at least 6 characters)
$('#new_user').validate({
rules: {
"user[name]": {
required: true,
minlength: 6,
remote:"/check_name"
}, ...
One caveat I'd like to add to the above rule is to allow a minimum of 2 Chinese characters OR 6 regular characters to pass the length test. (This is considered good usability for Chinese users, many of whom has 2-3 Chinese Character names in real life)
For example, I'd like the following names to pass the length test:
"张三"
"Michael"
and the following names to fail(due to being too short)
"张"
"Mike"
How do you write a custom javascript function to check for these conditions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
类似于:
有关详细信息,请参阅 Unicode 路线图 [1]
[1] http://unicode.org/roadmaps/bmp /
Something like :
See the Unicode Roadmap for details [1]
[1] http://unicode.org/roadmaps/bmp/
您可以使用 i国际化插件 以便您可以执行此测试:
然后,在您的函数中:
问候。
You can use the internationalization plugin so that you can do this test:
Then, in your function:
Regards.