/branches/versions/aipo702b/design/htmlmock/javascript/dojox/validate/web.xd.js

http://aipo.googlecode.com/ · JavaScript · 94 lines · 33 code · 14 blank · 47 comment · 3 complexity · 3fc8b4787c984c7f9ecde8531e29b836 MD5 · raw file

  1. dojo._xdResourceLoaded({
  2. depends: [["provide", "dojox.validate.web"],
  3. ["require", "dojox.validate._base"]],
  4. defineResource: function(dojo){if(!dojo._hasResource["dojox.validate.web"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  5. dojo._hasResource["dojox.validate.web"] = true;
  6. dojo.provide("dojox.validate.web");
  7. dojo.require("dojox.validate._base");
  8. dojox.validate.isIpAddress = function(/*String*/value, /*Object?*/flags) {
  9. // summary: Validates an IP address
  10. //
  11. // description:
  12. // Supports 5 formats for IPv4: dotted decimal, dotted hex, dotted octal, decimal and hexadecimal.
  13. // Supports 2 formats for Ipv6.
  14. //
  15. // value A string.
  16. // flags An object. All flags are boolean with default = true.
  17. // flags.allowDottedDecimal Example, 207.142.131.235. No zero padding.
  18. // flags.allowDottedHex Example, 0x18.0x11.0x9b.0x28. Case insensitive. Zero padding allowed.
  19. // flags.allowDottedOctal Example, 0030.0021.0233.0050. Zero padding allowed.
  20. // flags.allowDecimal Example, 3482223595. A decimal number between 0-4294967295.
  21. // flags.allowHex Example, 0xCF8E83EB. Hexadecimal number between 0x0-0xFFFFFFFF.
  22. // Case insensitive. Zero padding allowed.
  23. // flags.allowIPv6 IPv6 address written as eight groups of four hexadecimal digits.
  24. // flags.allowHybrid IPv6 address written as six groups of four hexadecimal digits
  25. // followed by the usual 4 dotted decimal digit notation of IPv4. x:x:x:x:x:x:d.d.d.d
  26. var re = new RegExp("^" + dojox.regexp.ipAddress(flags) + "$", "i");
  27. return re.test(value); // Boolean
  28. }
  29. dojox.validate.isUrl = function(/*String*/value, /*Object?*/flags) {
  30. // summary: Checks if a string could be a valid URL
  31. // value: A string
  32. // flags: An object
  33. // flags.scheme Can be true, false, or [true, false].
  34. // This means: required, not allowed, or either.
  35. // flags in regexp.host can be applied.
  36. // flags in regexp.ipAddress can be applied.
  37. // flags in regexp.tld can be applied.
  38. var re = new RegExp("^" + dojox.regexp.url(flags) + "$", "i");
  39. return re.test(value); // Boolean
  40. }
  41. dojox.validate.isEmailAddress = function(/*String*/value, /*Object?*/flags) {
  42. // summary: Checks if a string could be a valid email address
  43. //
  44. // value: A string
  45. // flags: An object
  46. // flags.allowCruft Allow address like <mailto:foo@yahoo.com>. Default is false.
  47. // flags in regexp.host can be applied.
  48. // flags in regexp.ipAddress can be applied.
  49. // flags in regexp.tld can be applied.
  50. var re = new RegExp("^" + dojox.regexp.emailAddress(flags) + "$", "i");
  51. return re.test(value); // Boolean
  52. }
  53. dojox.validate.isEmailAddressList = function(/*String*/value, /*Object?*/flags) {
  54. // summary: Checks if a string could be a valid email address list.
  55. //
  56. // value A string.
  57. // flags An object.
  58. // flags.listSeparator The character used to separate email addresses. Default is ";", ",", "\n" or " ".
  59. // flags in regexp.emailAddress can be applied.
  60. // flags in regexp.host can be applied.
  61. // flags in regexp.ipAddress can be applied.
  62. // flags in regexp.tld can be applied.
  63. var re = new RegExp("^" + dojox.regexp.emailAddressList(flags) + "$", "i");
  64. return re.test(value); // Boolean
  65. }
  66. dojox.validate.getEmailAddressList = function(/*String*/value, /*Object?*/flags) {
  67. // summary: Check if value is an email address list. If an empty list
  68. // is returned, the value didn't pass the test or it was empty.
  69. //
  70. // value: A string
  71. // flags: An object (same as dojo.validate.isEmailAddressList)
  72. if(!flags) { flags = {}; }
  73. if(!flags.listSeparator) { flags.listSeparator = "\\s;,"; }
  74. if ( dojox.validate.isEmailAddressList(value, flags) ) {
  75. return value.split(new RegExp("\\s*[" + flags.listSeparator + "]\\s*")); // Array
  76. }
  77. return []; // Array
  78. }
  79. }
  80. }});