ca.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.validate.ca"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.validate.ca"] = true;
  8. dojo.provide("dojox.validate.ca");
  9. /*=====
  10. dojox.validate.ca = {
  11. // summary: Module which includes Canadian-specific methods for dojox.validate
  12. }
  13. =====*/
  14. dojo.require("dojox.validate._base");
  15. dojo.mixin(dojox.validate.ca,{
  16. isPhoneNumber: function(/* String */value){
  17. // summary: Validates Canadian 10-digit phone number for several common formats
  18. return dojox.validate.us.isPhoneNumber(value); // Boolean
  19. },
  20. isProvince: function(/* String[2] */value) {
  21. // summary: Validates Canadian province abbreviations (2 characters)
  22. var re = new RegExp("^" + dojox.validate.regexp.ca.province() + "$", "i");
  23. return re.test(value); // Boolean
  24. },
  25. isSocialInsuranceNumber: function(/* String */value) {
  26. // summary: Validates Canadian 9 digit social insurance number for several
  27. // common formats
  28. //
  29. // description:
  30. // Validates Canadian 9 digit social insurance number for several
  31. // common formats. This routine only pattern matches and does not
  32. // use the Luhn Algorithm to validate number.
  33. //
  34. var flags = { format: [ "###-###-###", "### ### ###", "#########" ]};
  35. return dojox.validate.isNumberFormat(value, flags); // Boolean
  36. },
  37. isPostalCode: function(value) {
  38. // summary: Validates Canadian 6 digit postal code
  39. //
  40. // description:
  41. // Validates Canadian 6 digit postal code.
  42. // Canadian postal codes are in the format ANA NAN,
  43. // where A is a letter and N is a digit, with a space
  44. // separating the third and fourth characters.
  45. //
  46. var re = new RegExp("^" + dojox.validate.regexp.ca.postalCode() + "$", "i");
  47. return re.test(value); // Boolean
  48. }
  49. });
  50. }