入力された文字列を一文字づつ取出して半角だったらTrue、全角だったらFalseを返す。
1234567891011121314151617181920212223242526272829303132<
html
lang
=
"ja"
>
<
head
>
<
meta
http-equiv
=
"Content-Type"
content
=
"text/html; charset=Shift_JIS"
>
<
meta
http-equiv
=
"Content-Style-Type"
content
=
"text/css"
>
<
script
type
=
"text/javascript"
>
function isHalf(chara){
c=chara.charCodeAt(0);
if ( (c >= 0x0 && c <
0x81
) || (c == 0xf8f0) ||
(c >= 0xff61 && c <
0xffa0
) || (c >= 0xf8f1 && c <
0xf8f4
)) {
return true;
}
return false;
}
judge
=
function
(){
val
=
document
.getElementById("inputext").value;
ret
=
""
;
for(
i
=
0
;i<val.length;i++){
chara
=
val
.charAt(i);
ret+="("+chara+":"+isHalf(chara)+")";
}
document.getElementById("result")
.value
=
ret
;
//alert(ret);
}
</script>
<
title
></
title
>
</
head
>
<
body
>
<
input
type
=
"text"
size
=
"10"
id
=
"inputext"
>
<
button
id
=
"judge"
onclick
=
"judge()"
>Judge</
button
><
br
>
<
textarea
id
=
"result"
cols
=
"50"
rows
=
"10"
></
textarea
>
</
body
>
</
html
>