- is_hangul_char in javascript
- 자바스크립트에서 문자가 한글인지 확인
1 핵심 코드[ | ]
PHP
Copy
function is_hangul_char(ch) {
c = ch.charCodeAt(0);
if( 0x1100<=c && c<=0x11FF ) return true;
if( 0x3130<=c && c<=0x318F ) return true;
if( 0xAC00<=c && c<=0xD7A3 ) return true;
return false;
}
2 예제[ | ]
PHP
Copy
<!DOCTYPE html>
<meta charset="utf-8" />
<script>
function is_hangul_char(ch) {
c = ch.charCodeAt(0);
if( 0x1100<=c && c<=0x11FF ) return true;
if( 0x3130<=c && c<=0x318F ) return true;
if( 0xAC00<=c && c<=0xD7A3 ) return true;
return false;
}
function test(ch) {
document.write("<br>["+ch+"] is ");
if(is_hangul_char(ch)) document.write("hangul.");
else document.write("not hangul.");
}
test('A');
test(',');
test('★');
test('가');
test('ㄱ');
test('ㅏ');
test('힣');
test('日');
test('に');
</script>
- 실행결과
text
Copy
[A] is not hangul.
[,] is not hangul.
[★] is not hangul.
[가] is hangul.
[ㄱ] is hangul.
[ㅏ] is hangul.
[힣] is hangul.
[日] is not hangul.
[に] is not hangul.
3 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.
- 분류 댓글:
- JavaScript (13)
- UTF-8 (2)
HTML textarea 자동 높이 조절 ― …JavaScript 랜덤 한글 ― JmnoteJavaScript 랜덤 한글 ― JmnoteJavaScript 랜덤 한글 ―Pinkcrimson
JavaScript 랜덤 한글 ― MywikierJavaScript 변수 ― Nathan on zetawikiJavaScript 변수 ― John JeongJavaScript 변수 ― SotoZeroClipboard 사용하기 ― LilisZeroClipboard 사용하기 ― Jmnote자바스크립트 HTML 테이블 행 추가/삭제 ― Pilming자바스크립트 HTML 테이블 행 추가/삭제 ― Jmnote자바스크립트 웹페이지 읽기 ― …