numutil.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: pps
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2017
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. // Number Utilities
  9. function CNumUtil() {};
  10. CNumUtil.normalizeDecimal = function (str) {
  11. if ( decimalpt != "." )
  12. {
  13. var reg = new RegExp(decimalpt, "g");
  14. str = str.replace(reg, ".");
  15. }
  16. return str;
  17. }
  18. CNumUtil.validateNumField = function (FormObj, acceptDecimal, validChars)
  19. {
  20. var userInput = FormObj.value;
  21. var reducedInput = "";
  22. var len = userInput.length;
  23. for ( var i = 0; i < len; i++ ) { //Strip out the thousand Separators.
  24. if (userInput.charAt(i) != thousandsep) {
  25. reducedInput += userInput.charAt(i);
  26. }
  27. }
  28. FormObj.value = reducedInput;
  29. //check for invalid characters if valid range was specified!!!
  30. if( !(typeof validChars == "undefined") && validChars != null && validChars.length > 0 && reducedInput.length > 0 )
  31. {
  32. var pos;
  33. pos = reducedInput.search(eval(validChars));
  34. if (pos != -1)
  35. return false;
  36. }
  37. var nInput = Number(this.normalizeDecimal(reducedInput));
  38. if(isNaN(nInput))
  39. return false;
  40. if(!acceptDecimal && (Math.ceil(nInput) != nInput))
  41. return false;
  42. return true;
  43. }
  44. CNumUtil.localizeDecimal = function(str)
  45. {
  46. if ( decimalpt != "." )
  47. {
  48. str = str.replace( ".", decimalpt );
  49. }
  50. return str;
  51. }