When ASP.NET programmers don't know JavaScript
-
You find this in the overlong validation routines...
function isNumeric(strString) {
var strValidChars = "0123456789";
var strChar;
var blnResult = true;for (i = 0; i < strString.length && blnResult == true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = false; } } return blnResult;
}
Developer, meet
isNaN()
,isNaN()
meet developer. -
You find this in the overlong validation routines...
function isNumeric(strString) {
var strValidChars = "0123456789";
var strChar;
var blnResult = true;for (i = 0; i < strString.length && blnResult == true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = false; } } return blnResult;
}
Developer, meet
isNaN()
,isNaN()
meet developer.Nice. Very useful with empty strings.
-
You find this in the overlong validation routines...
function isNumeric(strString) {
var strValidChars = "0123456789";
var strChar;
var blnResult = true;for (i = 0; i < strString.length && blnResult == true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = false; } } return blnResult;
}
Developer, meet
isNaN()
,isNaN()
meet developer. -
You find this in the overlong validation routines...
function isNumeric(strString) {
var strValidChars = "0123456789";
var strChar;
var blnResult = true;for (i = 0; i < strString.length && blnResult == true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = false; } } return blnResult;
}
Developer, meet
isNaN()
,isNaN()
meet developer.But there's a functionality difference here, which might be deliberate. isNan handles decimal points and minus signs, the example function does not.
-
You find this in the overlong validation routines...
function isNumeric(strString) {
var strValidChars = "0123456789";
var strChar;
var blnResult = true;for (i = 0; i < strString.length && blnResult == true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = false; } } return blnResult;
}
Developer, meet
isNaN()
,isNaN()
meet developer.gkushner wrote:
Developer, meet isNaN
Nope. isNaN takes a float/double as an input, all it does is keep track of a mathematical mishap, such as taking the logarithm of a negative number. It does not deal with a string that may or may not represent something that is considered a valid number (before you can apply isNaN, you have to try and parse the string to a number, and that is what the code is about) :)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
-
You find this in the overlong validation routines...
function isNumeric(strString) {
var strValidChars = "0123456789";
var strChar;
var blnResult = true;for (i = 0; i < strString.length && blnResult == true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = false; } } return blnResult;
}
Developer, meet
isNaN()
,isNaN()
meet developer.Regex
-
Regex
Bingo!
-
You find this in the overlong validation routines...
function isNumeric(strString) {
var strValidChars = "0123456789";
var strChar;
var blnResult = true;for (i = 0; i < strString.length && blnResult == true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = false; } } return blnResult;
}
Developer, meet
isNaN()
,isNaN()
meet developer.That is a great horror! Not only is it completely bloated and demonstrating the lack of understanding for weak typing and implicit conversion in JS, but it's also a horrifically inefficient implementation of a function parsing an integer. The naming convention is the icing on the cake. At least this person wasn't trying to open a window on the server-side or accessing session on the client. Many asp.net programmers (in no small part due to Microsoft's tendency to present asp.net as if it was windows forms programming in introductory classes, I suspect) seem to not even understand any of the implications of a client-server model...
-
gkushner wrote:
Developer, meet isNaN
Nope. isNaN takes a float/double as an input, all it does is keep track of a mathematical mishap, such as taking the logarithm of a negative number. It does not deal with a string that may or may not represent something that is considered a valid number (before you can apply isNaN, you have to try and parse the string to a number, and that is what the code is about) :)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
Well, actually JavaScript will try to cast a string provided to isNaN as a float. So, if you write isNaN("10"), js will process the expression as isNaN(parseFloat("10")). However isNaN(parseInt("10")) gets the job done.
-
You find this in the overlong validation routines...
function isNumeric(strString) {
var strValidChars = "0123456789";
var strChar;
var blnResult = true;for (i = 0; i < strString.length && blnResult == true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = false; } } return blnResult;
}
Developer, meet
isNaN()
,isNaN()
meet developer.