us.js 2.0 KB

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