验证多语言网址-日语langauga [英] Validate url for multilingual - Japanese langauga
问题描述
我具有在表单中添加wesbsite选项的功能.
用户可以在此处编写域/url,并且该域/url可以是英语,也可以是日语,如下所示.
www.google.com
www.南极星.com
I am using following validation for english domains
for (var j = 0; j < dname.length; j++) {
var dh = dname.charAt(j);
var hh = dh.charCodeAt(0);
/*if(dh!='.'){
var chkip=chkip+dh;
}*/
if ((hh > 47 && hh < 59) || (hh > 64 && hh < 91) || (hh > 96 && hh < 123) || hh == 45 || hh == 46) {
var index2 = dname.indexOf('www.');
if (index2 != -1) {
dname = dname.substring(index2 + 4);
if (dname.charAt(0) == '-') {
error_msg = '\'-\'' + window.gt.gettext('not_allowed_in_beginning');
return error_msg;
}
}
if ((j == 0 || j == dname.length - 1) && hh == 45) {
//if(hh == 45){
error_msg = '\'-\'' + window.gt.gettext('not_allowed_in_beginning');
}
} else {
error_msg = window.gt.gettext('cmnscrpt_domname_inval');
}
}
我可以写些什么来验证日语域?
有一种非常简单的方法,可以将所有的RegEx逻辑(一个人可以很容易地用英语应用)应用到使用Unicode的任何语言.
要匹配所有字母[A-Za-z]之类的Unicode字符,我们可以使用
[\ u0041- \ u005A],其中 \ u0041 是 A 的十六进制代码,而 \ u005A 是的十六进制代码Z
'matchCAPS leTTer'.match(/[\u0041-\u005A]+/g)
//output ["CAPS", "TT"]
以相同的方式,我们可以根据unicode.org提供的其他十六进制顺序(例如:\ u0A10到\ u0A1F)使用其他Unicode字符或等效的十六进制代码
下面是用于网址验证的regEx
url.match(/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/)
您只需将 a-z,A-Z,0-9 替换为日语Unicode 集中的相似字符,即可正常使用. 我不懂日语:)
I have feature to add wesbsite option in form.
Here user can write domain /url and this domain/url can be in English as well Japanese language as below.
www.google.com
www.南极星.com
I am using following validation for english domains
for (var j = 0; j < dname.length; j++) {
var dh = dname.charAt(j);
var hh = dh.charCodeAt(0);
/*if(dh!='.'){
var chkip=chkip+dh;
}*/
if ((hh > 47 && hh < 59) || (hh > 64 && hh < 91) || (hh > 96 && hh < 123) || hh == 45 || hh == 46) {
var index2 = dname.indexOf('www.');
if (index2 != -1) {
dname = dname.substring(index2 + 4);
if (dname.charAt(0) == '-') {
error_msg = '\'-\'' + window.gt.gettext('not_allowed_in_beginning');
return error_msg;
}
}
if ((j == 0 || j == dname.length - 1) && hh == 45) {
//if(hh == 45){
error_msg = '\'-\'' + window.gt.gettext('not_allowed_in_beginning');
}
} else {
error_msg = window.gt.gettext('cmnscrpt_domname_inval');
}
}
what can I write to validate Japanese domain ?
There is a very simple method to apply all you RegEx logic(that one can apply easily in English) for any Language using Unicode.
For matching a range of Unicode Characters like all Alphabets [A-Za-z] we can use
[\u0041-\u005A] where \u0041 is Hex-Code for A and \u005A is Hex Code for Z
'matchCAPS leTTer'.match(/[\u0041-\u005A]+/g)
//output ["CAPS", "TT"]
In the same way we can use other Unicode characters or their equivalent Hex-Code according to their Hexadecimal Order (eg: \u0A10 to \u0A1F) provided by unicode.org
Below is a regEx for url validation
url.match(/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/)
you just replace a-z, A-Z, 0-9 with the similar characters from Japanese Unicode set and it will work fine. I don't know Japanese :)
这篇关于验证多语言网址-日语langauga的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!