웹마스터 팁
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
숫자인지 아닌지 알아보는함수
2003.04.27 20:30
isNaN(검사할자료)
isNaN함수는 주어진 자료가 문자열일땐 true 를 반환하고 숫자일땐 false 를 반환합니다. 소수점도 false 나옵니다.
<script>
xxx=234234;
if(isNaN(xxx))
{
document.write(isNaN(xxx));
document.write(숫자아님);
}
else
{
document.write(isNaN(xxx));
document.write(숫자임);
}
</script>
isNaN함수는 주어진 자료가 문자열일땐 true 를 반환하고 숫자일땐 false 를 반환합니다. 소수점도 false 나옵니다.
<script>
xxx=234234;
if(isNaN(xxx))
{
document.write(isNaN(xxx));
document.write(숫자아님);
}
else
{
document.write(isNaN(xxx));
document.write(숫자임);
}
</script>
xxx=234234;
alert(typeof xxx);
xxx="java";
alert(typeof xxx);
</script>
첫번째 출력결과: "number"
두번째 출력결과: "string"
참고가 되셨길 바랍니다.