bdb19576e8877cc3ce4ff37e43d47a9777d0182d.svn-base 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. if (!dojo._hasResource["dojox.validate.us"]) { // _hasResource checks added by
  2. // build. Do not use
  3. // _hasResource directly in your
  4. // code.
  5. dojo._hasResource["dojox.validate.us"] = true;
  6. dojo.provide("dojox.validate.us");
  7. dojo.require("dojox.validate._base");
  8. dojox.validate.us.isState = function(/* String */value, /* Object? */flags) {
  9. // summary: Validates US state and territory abbreviations.
  10. //
  11. // value: A two character string
  12. // flags: An object
  13. // flags.allowTerritories Allow Guam, Puerto Rico, etc. Default is true.
  14. // flags.allowMilitary Allow military 'states', e.g. Armed Forces Europe
  15. // (AE). Default is true.
  16. var re = new RegExp("^" + dojox.regexp.us.state(flags) + "$", "i");
  17. return re.test(value); // Boolean
  18. }
  19. dojox.validate.us.isPhoneNumber = function(/* String */value) {
  20. // summary: Validates 10 US digit phone number for several common
  21. // formats
  22. // value: The telephone number string
  23. var flags = {
  24. format : ["###-###-####", "(###) ###-####", "(###) ### ####",
  25. "###.###.####", "###/###-####", "### ### ####",
  26. "###-###-#### x#???", "(###) ###-#### x#???",
  27. "(###) ### #### x#???", "###.###.#### x#???",
  28. "###/###-#### x#???", "### ### #### x#???", "##########"]
  29. };
  30. return dojox.validate.isNumberFormat(value, flags); // Boolean
  31. }
  32. dojox.validate.us.isSocialSecurityNumber = function(/* String */value) {
  33. // summary: Validates social security number
  34. var flags = {
  35. format : ["###-##-####", "### ## ####", "#########"]
  36. };
  37. return dojox.validate.isNumberFormat(value, flags); // Boolean
  38. }
  39. dojox.validate.us.isZipCode = function(/* String */value) {
  40. // summary: Validates U.S. zip-code
  41. var flags = {
  42. format : ["#####-####", "##### ####", "#########", "#####"]
  43. };
  44. return dojox.validate.isNumberFormat(value, flags); // Boolean
  45. }
  46. }