Validating percentage values in jquery

To validate 100% value in textbox using juery focusout event.We can display error message in alert message window

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/jquery-3.1.1.js"></script>
    <script src="Scripts/jquery.validate.js"></script>
</head>
<body>
    <div>
        <input type="text" id="txtboxId"></div>
    <script>
        $('input[id$="txtboxId"]').focusout(functionname);
   function functionname(sender, args) {
      var maxKPIPercentage = 100;
      var totalKPIPercentage = 0;
      $('input[id$="txtboxId"]').each(function () {
         if ($.trim($(this).val()).length > 0) {
           var ctrlVaL = $.trim($(this).val()).replace(/[%,]+/g'');
           totalKPIPercentage = totalKPIPercentage + parseFloat(ctrlVaL);
                };
            });
            if (totalKPIPercentage > parseFloat(maxKPIPercentage))
                alert("KPI Percentage Exceeded");
            event.stopPropagation();
        }
    </script>
</body>
</html> 
 
Validating percentage values in jquery
 
 

Comments