﻿// 문자열 바이트 검사
String.prototype.bytes = function() 
{
	var l = 0;
	
	for (var i=0; i<this.length; i++) 
	    l += (escape(this.charCodeAt(i)).length > 4) ? 2 : 1;
	
	return l;
}

// 공백제거
String.prototype.trim = function() {
  return this.replace(/(^\s*)|(\s*$)|($\s*)/g, "");
}

// 문자열의 바이트 수
String.prototype.getBytes = function(){
    return this.bytes();
}

// 문자열이 존재하는지 검사
String.prototype.isNullorEmpty = function() {
    if(this == null) return true;
    if(this == 'undefined') return true;
    if(this.trim() == '') return true;
    return false;
}

// 문자열 전체가 숫자인지 판단
String.prototype.isNumber = function() {
	var pattern = /^[0-9]+$/;
	return pattern.test(this);
}

// 문자열 전체가 한글인지 판단
String.prototype.isKorean = function() {
	var pattern = /^[ㄱ-힣]+$/;
	return pattern.test(this);
}

// 문자열 전체가 영문인지 판단
String.prototype.isEnglish = function() {
	var pattern = /^[a-zA-Z]+$/;
	return pattern.test(this);
}

// 문자열이 한글과 영문인지 판단
String.prototype.isKorEng = function() {
	var pattern = /^[ㄱ-힣a-zA-Z]+$/;
	return pattern.test(this);
}

// 문자열이 한글과 숫자인지 판단
String.prototype.isKorNum = function() {
	var pattern = /^[0-9ㄱ-힣]+$/;
	return pattern.test(this);
}

// 문자열이 영문과 숫자인지 판단
String.prototype.isEngNum = function() {
	var pattern = /^[a-zA-Z0-9]+$/;
	return pattern.test(this);
}

// 문자열이 지정한 길이인지 판단
String.prototype.isLimitLength = function(len) {
    return this.length == len;
}

// 문자열이 지정한 범위의 길이인지 판단
String.prototype.isRangeLength = function(minLen, maxLen) {
    return this.length > minLen && this.length < maxLen;
}
