본문 바로가기
jQuery

jQeury isNumeric 함수를 이용한 숫자 여부 판단

by Dokon Jang 2021. 8. 10.
반응형

jQeury의 isNumeric 함수로 숫자 여부를 판단 할 수 있습니다.

// true (numeric)
$.isNumeric( "-10" );
$.isNumeric( "0" );
$.isNumeric( 0xFF );
$.isNumeric( "0xFF" );
$.isNumeric( "8e5" );
$.isNumeric( "3.1415" );
$.isNumeric( +10 );
$.isNumeric( 0144 );
 
// false (non-numeric)
$.isNumeric( "-0x42" );
$.isNumeric( "7.2acdgs" );
$.isNumeric( "" );
$.isNumeric( {} );
$.isNumeric( NaN );
$.isNumeric( null );
$.isNumeric( true );
$.isNumeric( Infinity );
$.isNumeric( undefined );

 

예제 전체 소스

<html>
<head>
	<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
	<script type="text/javascript">
		// true (numeric)
		console.log('$.isNumeric( "-10" ) : ' + $.isNumeric( "-10" ));
		console.log('$.isNumeric( "0" ) : ' + $.isNumeric( "0" ));
		console.log('$.isNumeric( 0xFF ) : ' + $.isNumeric( 0xFF ));
		console.log('$.isNumeric( "0xFF" ) : ' + $.isNumeric( "0xFF" ));
		console.log('$.isNumeric( "8e5" ) : ' + $.isNumeric( "8e5" ));
		console.log('$.isNumeric( "3.1415" ) : ' + $.isNumeric( "3.1415" ));
		console.log('$.isNumeric( +10 ) : ' + $.isNumeric( +10 ));
		console.log('$.isNumeric( 0144 ) : ' + $.isNumeric( 0144 ));
		 
		// false (non-numeric)
		console.log('$.isNumeric( "-0x42" ) : ' + $.isNumeric( "-0x42" ));
		console.log('$.isNumeric( "7.2acdgs" ) : ' + $.isNumeric( "7.2acdgs" ));
		console.log('$.isNumeric( "" ) : ' + $.isNumeric( "" ));
		console.log('$.isNumeric( {} ) : ' + $.isNumeric( {} ));
		console.log('$.isNumeric( NaN ) : ' + $.isNumeric( NaN ));
		console.log('$.isNumeric( null ) : ' + $.isNumeric( null ));
		console.log('$.isNumeric( true ) : ' + $.isNumeric( true ));
		console.log('$.isNumeric( Infinity ) : ' + $.isNumeric( Infinity ));
		console.log('$.isNumeric( undefined ) : ' + $.isNumeric( undefined ));
	</script>
</head>

<body>
</body>
</html>
반응형

'jQuery' 카테고리의 다른 글

jQuery로 html select에 readonly 효과 주기  (0) 2021.07.29
JQuery AJAX 사용 시 한글 깨지는 현상 해결방법  (0) 2021.07.22
jQeury 기본 Syntax  (0) 2017.03.21
jQuery 시작하기.  (0) 2017.03.21

댓글