我需要禁止在输入字段中写入全角日语字符,半角可以,除全角之外的任何其他符号都可以。
在这里https://gist.github.com/terrancesnyder/1345094 我找到了全角片假名(zenkaku ??)的正则表达式就够了吗?目前我的代码看起来像这样
if ( /[?-?]/.test("??") ) {
console.log('full width');
}else{
console.log('not full width');
}
Run Code Online (Sandbox Code Playgroud)
我不熟悉日语所以我不知道我还需要检查什么,我的意思是他们有片假名、平假名等等,这就是为什么我不确定我的剧本是否足够好,请告诉我你怎么看
日语使用很多这种字符。
\ne.g.
使用简单的正则表达式无法检测到它。\n其他亚洲语言中也存在字符宽度的变化。\n在 Unicode 中,它被定义为“东亚宽度”。
\n\nUnicodedata module of python通常用于确定“东亚宽度”。\nJavaScript 的标准函数中不存在类似的东西。
但是,有一些npm 模块。\n如果你使用这个East Asian Width模块可以这样确定。
var eaw = require(\'eastasianwidth\');\nfunction isHalfWidth(c){ return eaw.length(c) == 1; }\n\nisHalfWidth("\xe3\x81\x82")\n// -> false\nisHalfWidth("\xef\xbd\xb1")\n// -> true\nisHalfWidth("\xef\xbc\xa1")\n// -> false\nisHalfWidth("A")\n/// -> true\nRun Code Online (Sandbox Code Playgroud)\n