티스토리 뷰

🌈 JavaScript

isNumber

James Wetzel 2023. 2. 23. 16:00
728x90
반응형
Utils.IsNumeric = function(value) {
	var ValidChars = "-.,0123456789";
	var IsNumber = true;
	var Char;

	if (typeof (value) == "undefined") return false;
	if (typeof (value) != "number" && value == "") return false;

	for (i = 0; i < value.length && IsNumber == true; i++) {
		Char = value.charAt(i);
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
};

//자연수값
Utils.IsNumber = function (value) {
	var ValidChars = "0123456789";
	var IsNumber = true;
	var Char;

	if (typeof (value) == "undefined") return false;
	if (typeof (value) != "number" && value == "") return false;

	for (i = 0; i < value.length && IsNumber == true; i++) {
		Char = value.charAt(i);
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
};
728x90
반응형