Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. When ASP.NET programmers don't know JavaScript

When ASP.NET programmers don't know JavaScript

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpjavascriptasp-net
10 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gordon Kushner
    wrote on last edited by
    #1

    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.

    P J E L P 7 Replies Last reply
    0
    • G Gordon Kushner

      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.

      P Offline
      P Offline
      Paulo Zemek
      wrote on last edited by
      #2

      Nice. Very useful with empty strings.

      1 Reply Last reply
      0
      • G Gordon Kushner

        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.

        J Offline
        J Offline
        Jeroen De Dauw
        wrote on last edited by
        #3

        isNaD() would return true for sure.

        Jeroen De Dauw --- Forums ; Blog ; Wiki --- 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!

        1 Reply Last reply
        0
        • G Gordon Kushner

          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.

          E Offline
          E Offline
          Electron Shepherd
          wrote on last edited by
          #4

          But there's a functionality difference here, which might be deliberate. isNan handles decimal points and minus signs, the example function does not.

          Server and Network Monitoring

          1 Reply Last reply
          0
          • G Gordon Kushner

            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.

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            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!


            R 1 Reply Last reply
            0
            • G Gordon Kushner

              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.

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              Regex

              G 1 Reply Last reply
              0
              • P PIEBALDconsult

                Regex

                G Offline
                G Offline
                Gordon Kushner
                wrote on last edited by
                #7

                Bingo!

                1 Reply Last reply
                0
                • G Gordon Kushner

                  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.

                  D Offline
                  D Offline
                  dojohansen
                  wrote on last edited by
                  #8

                  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...

                  1 Reply Last reply
                  0
                  • L Luc Pattyn

                    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!


                    R Offline
                    R Offline
                    robocodeboy
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • G Gordon Kushner

                      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.

                      L Offline
                      L Offline
                      Lutoslaw
                      wrote on last edited by
                      #10

                      gkushner wrote:

                      var strChar;

                      I hate weak-typing. :doh:

                      Greetings - Jacek

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups