简体   繁体   English

如何在jQuery上检查最少的泰语单词

[英]How to check minimum thai words on jquery

I have problem with detecting minimum words using jquery.validation.js. 我在使用jquery.validation.js检测最小单词时遇到问题。 As i got a script for uses this on english: 当我得到一个用于英语的脚本时:

jQuery.validator.addMethod('minWords', function(value, element, params) {
   return !$(element).val() || $(element).val().match(/\b\w+\b/g).length >= params;
}, 'Please enter at least {0} words.');

This script NOT WORK on thai specific language. 该脚本不适用于泰国特定语言。 Can anybody help me? 有谁能够帮助我?

Thanks 谢谢


It's work now. 现在正在工作。 Thanks All 谢谢大家

It's not working because Thai characters are Unicode characters. 它不起作用,因为泰语字符是Unicode字符。 Sadly, Javascript has no built in Unicode regex functionality but there is a great plugin that does the trick: 可悲的是,Javascript没有内置的Unicode regex功能,但是有一个出色的插件可以解决这个问题:

XRegExp - The one of a kind JavaScript regular expression library XRegExp-一种JavaScript正则表达式库

Check out the documentation for the usage of XRegExp. 请查阅有关XRegExp用法的文档。

Finally, I counted the thai language without XRegxp, I'm modifying minWords plugin using the same method from jquery.wordcount.js. 最后,我计算了没有XRegxp的泰语,我正在使用jquery.wordcount.js中的相同方法修改minWords插件。 Here's the complete modified script: 这是完整的修改后的脚本:

jQuery.validator.addMethod('minWords', function(value, element, params) {
    return !$(element).val() || $(element).val().split(/[\s\.\?]+/).length >= params;
}, 'Please enter at least {0} words.');

Here's the regular expression: 这是正则表达式:

split(/[\s\.\?]+/)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM