validation.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: ps
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2011
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  9. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  10. //Functions used in client side validation
  11. function CAFSelectText(field, text) {
  12. field.focus();
  13. if (text.length > 0) {
  14. if (field.createTextRange) {
  15. var textrange = field.createTextRange();
  16. if (textrange != null) {
  17. textrange.moveStart("character", -1);
  18. textrange.findText(text);
  19. textrange.select();
  20. textrange.scrollIntoView();
  21. }
  22. } else {
  23. var startIdx = field.value.indexOf(text);
  24. var endIdx = startIdx + text.length;
  25. field.setSelectionRange(startIdx, endIdx);
  26. }
  27. }
  28. }
  29. /**
  30. * Checks if the given value is an integer
  31. * Note: use regular expression in order to avoid any server CAF error
  32. * @param value
  33. * @param unsigned indicates if it is unsigned or not
  34. * @return true if it is, false otherwise
  35. */
  36. function CAFisInteger(value, unsigned) {
  37. var isInteger = false;
  38. var regExp = null;
  39. if (value != null && value != "") {
  40. if (unsigned) {
  41. regExp = new RegExp("^[0-9]+$");
  42. } else {
  43. regExp = new RegExp("^-?[0-9]+$");
  44. }
  45. isInteger = regExp.test(value);
  46. }
  47. return isInteger;
  48. }
  49. function CAFReportValidationError(msg) {
  50. alert(msg);
  51. }