String.prototype.atrim = function()
{
return this.replace(/\s/g,'');
}
모든 공백을 제거한 후 값을 반환한다.
사용 예 : document.getElementById("id").value = document.getElementById("id").value.atrim();
<input type="text" onblur="this.value=this.value.atrim()" />
String.prototype.atrim = function()
{
return this.replace(/\s/g,'');
}
모든 공백을 제거한 후 값을 반환한다.
사용 예 : document.getElementById("id").value = document.getElementById("id").value.atrim();
<input type="text" onblur="this.value=this.value.atrim()" />
별명(닉네임) 입력 글자를 확인하는 자바스크립트 정규식으로
한글, 영문, 숫자만 입력할 수 있다.
function nick_chk(str)
{
if(str.length < 2 || str.length > 10) {
alert("2~10자의 한글, 영문, 숫자만 사용할 수 있습니다.");
return false;
}
var chk = /[0-9]|[a-z]|[A-Z]|[가-힣]/;
for( var i = 0; i <= str.length -1 ; i++ )
{
if(chk.test(str.charAt(i)))
{
}
else
{
alert("2~10자의 한글, 영문, 숫자만 사용할 수 있습니다.");
return false;
}
}
return true;
}
<input type="text" id="nick" name="nick" maxlength="10" onblur="nick_chk(this.value);" />