Programming Challenge 17
HTML
<script src="https://cdn.jsdelivr.net/npm/xregexp@4.1.1/xregexp-all.js"></script>
<div style="display:none;">
Internationalised Programming Challenge 17
국제화 된 프로그래밍 챌린지 열일곱
The task in this challenge is to validate names using regular expressions (regex). Using regex we can perform basic syntax validation. Checking whether a name is actually correct would require a supporting database of correct names and/or correct components of a name.
Chinese Names
My validation rules for the Chinese name are: the name should consist of 2 or 3 or 4 Chinese characters without any intervening space(s).
My validation rules for a Romanised Chinese name are: The given name and the family name are space separated, a given name or a family name can be hyphenated, tone marks are allowed.
Khmer Names
I check for a family name followed by a given name or vice versa and that the names consist of Khmer letters only.
Korean Names
Korean names validation is a team effort by Siqing Geng 耿思晴, Yiming Huang 黄一鸣, Jinze Huo 霍金泽, Guoxu Wang 王国旭 and myself.
Korean Name rules are: Family name followed by given name. The family name is 1 or 2 hangul syllables. There are no intervening spaces in the name unless the family name is 2 hangul syllables, in which case, there is a space after the family name. The longest given name I have so far found is 19 hangul syllables.
Korean Hanja 한자 Name rules are: In principle, each hangul syllable, could have a Hanja character. Hanja does not use spaces. Based on the maximum name length from Korean Name rules above, the permissible Hanja names are 2 to 21 Hanja with no intervening spaces. Not every Korean person has a Hanja name.
Korean Romanised Name rules are: Family name followed by given name or vice versa. The family name, if 2 syllables, may have a hypen between the syllables. The given name syllables may have intervening spaces or hyphens. Each syllable is romanised as 2 to 6 letters. Questions...
CSS
body{
background-color:Thistle;
}
h2{
line-height:60%;
}
.textys{
font-size:15pt;
margin-left:4px;
}
.spannys{
font-size:15pt;
}
.단추{
margin:8px 0 0 2px;
font-size:15pt;
border-radius:12px;
box-shadow: 3px 3px gray;
background-color:LightPink;
}
.단추:hover{
background-color:#ffffbb;
cursor:pointer;
}
.图像{
vertical-align:text-bottom;
}
JavaScript
function validateChineseName(){
var regexPattern=XRegExp("^((?!\\p{InKangxi_Radicals}|\\p{InCJK_Radicals_Supplement}|\\p{InCJK_Symbols_and_Punctuation})\\p{Han}){1,}\s$","A");
if(regexPattern.test(document.getElementById('汉字').value)){
spannyZh1.innerHTML=" is valid";
}else{
spannyZh1.innerHTML=" is NOT valid";
}
}
function validateRomanisedChineseName(){
var regexPattern=RegExp("^[a-züāēīōūǖáéíóúǘǎěǐǒǔǚàèìòùǜ]{1,6}((\-[a-züāēīōūǖáéíóúǘǎěǐǒǔǚàèìòùǜ]{1,6})|(\\s?[a-züāēīōūǖáéíóúǘǎěǐǒǔǚàèìòùǜ]{1,6}))?\\s[a-züāēīōūǖáéíóúǘǎěǐǒǔǚàèìòùǜ]{1,6}((\-[a-züāēīōūǖáéíóúǘǎěǐǒǔǚàèìòùǜ]{1,6})|(\\s?[a-züāēīōūǖáéíóúǘǎěǐǒǔǚàèìòùǜ]{1,6}))?$","ui");
if(regexPattern.test(document.getElementById('罗马化').value.normalize("NFC"))){
spannyZh2.innerHTML=" is valid";
}else{
spannyZh2.innerHTML=" is NOT valid";
}
}
function validateKhmerName(){
var regexPattern=XRegExp("^(\\p{InKhmer}(?<![\\p{N}\\p{P}\\p{Sc}]))+\\s(\\p{InKhmer}(?<![\\p{N}\\p{P}\\p{Sc}]))+$","u");
if(regexPattern.test(document.getElementById('ភាសាខ្មែរ').value)){
spannyKm.innerHTML=" is valid";
}else{
spannyKm.innerHTML=" is NOT valid";
}
}
function validateKoreanName(){
var regexPattern=XRegExp("^\\p{InHangul_Syllables}(\\p{InHangul_Syllables}\\s)?\\p{InHangul_Syllables}{1,19}$","u");
if(regexPattern.test(document.getElementById('한글').value)){
spannyKo1.innerHTML=" is valid";
}else{
spannyKo1.innerHTML=" is NOT valid";
}
}
function validateHanjaName(){
var regexPattern=XRegExp("^((?!\\p{InKangxi_Radicals}|\\p{InCJK_Radicals_Supplement}|\\p{InCJK_Symbols_and_Punctuation})\\p{Han}){2,21}$","A");
if(regexPattern.test(document.getElementById('한자').value)){
spannyKo2.innerHTML=" is valid";
}else{
spannyKo2.innerHTML=" is NOT valid";
}
}
function validateRomanisedName(){
var regexPattern=RegExp("^(([a-z]{1,6}(-?[a-z]{1,6})?\\s([a-z]{1,6}[\-\\s]?){0,18}[a-z]{1,6})|(([a-z]{1,6}[\-\\s]?){0,18}[a-z]{1,6}\\s[a-z]{1,6}(-?[a-z]{1,6})?))$","i");
...