ca.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. define("dojox/validate/ca", ["dojo/_base/lang", "./_base", "./regexp", "./us"],
  2. function(lang, validate, xregexp, us){
  3. /*=====
  4. dojox.validate.ca = {
  5. // summary: Module which includes Canadian-specific methods for dojox.validate
  6. }
  7. =====*/
  8. var ca = lang.getObject("ca", true, validate);
  9. lang.mixin(ca, {
  10. isPhoneNumber: function(/* String */value){
  11. // summary: Validates Canadian 10-digit phone number for several common formats
  12. return us.isPhoneNumber(value); // Boolean
  13. },
  14. isProvince: function(/* String[2] */value) {
  15. // summary: Validates Canadian province abbreviations (2 characters)
  16. var re = new RegExp("^" + xregexp.ca.province() + "$", "i");
  17. return re.test(value); // Boolean
  18. },
  19. isSocialInsuranceNumber: function(/* String */value) {
  20. // summary: Validates Canadian 9 digit social insurance number for several
  21. // common formats
  22. //
  23. // description:
  24. // Validates Canadian 9 digit social insurance number for several
  25. // common formats. This routine only pattern matches and does not
  26. // use the Luhn Algorithm to validate number.
  27. //
  28. var flags = { format: [ "###-###-###", "### ### ###", "#########" ]};
  29. return validate.isNumberFormat(value, flags); // Boolean
  30. },
  31. isPostalCode: function(value) {
  32. // summary: Validates Canadian 6 digit postal code
  33. //
  34. // description:
  35. // Validates Canadian 6 digit postal code.
  36. // Canadian postal codes are in the format ANA NAN,
  37. // where A is a letter and N is a digit, with a space
  38. // separating the third and fourth characters.
  39. //
  40. var re = new RegExp("^" + xregexp.ca.postalCode() + "$", "i");
  41. return re.test(value); // Boolean
  42. }
  43. });
  44. return ca;
  45. });