cc841de89b5f457fef4e8055ebc2df4c0da244e5.svn-base 3.7 KB

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