us.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. define("dojox/validate/us", ["dojo/_base/lang", "./_base", "./regexp"],
  2. function(lang, validate, xregexp){
  3. var us = lang.getObject("us", true, validate);
  4. us.isState = function(/*String*/value, /*Object?*/flags){
  5. // summary: Validates US state and territory abbreviations.
  6. //
  7. // value: A two character string
  8. // flags: An object
  9. // flags.allowTerritories Allow Guam, Puerto Rico, etc. Default is true.
  10. // flags.allowMilitary Allow military 'states', e.g. Armed Forces Europe (AE). Default is true.
  11. var re = new RegExp("^" + xregexp.us.state(flags) + "$", "i");
  12. return re.test(value); // Boolean
  13. };
  14. us.isPhoneNumber = function(/*String*/value){
  15. // summary: Validates 10 US digit phone number for several common formats
  16. // value: The telephone number string
  17. var flags = {
  18. format: [
  19. "###-###-####",
  20. "(###) ###-####",
  21. "(###) ### ####",
  22. "###.###.####",
  23. "###/###-####",
  24. "### ### ####",
  25. "###-###-#### x#???",
  26. "(###) ###-#### x#???",
  27. "(###) ### #### x#???",
  28. "###.###.#### x#???",
  29. "###/###-#### x#???",
  30. "### ### #### x#???",
  31. "##########"
  32. ]
  33. };
  34. return validate.isNumberFormat(value, flags); // Boolean
  35. };
  36. us.isSocialSecurityNumber = function(/*String*/value){
  37. // summary: Validates social security number
  38. var flags = {
  39. format: [
  40. "###-##-####",
  41. "### ## ####",
  42. "#########"
  43. ]
  44. };
  45. return validate.isNumberFormat(value, flags); // Boolean
  46. };
  47. us.isZipCode = function(/*String*/value){
  48. // summary: Validates U.S. zip-code
  49. var flags = {
  50. format: [
  51. "#####-####",
  52. "##### ####",
  53. "#########",
  54. "#####"
  55. ]
  56. };
  57. return validate.isNumberFormat(value, flags); // Boolean
  58. };
  59. return us;
  60. });