jquery.validationEngine-en.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. (function ($) {
  2. $.fn.validationEngineLanguage = function () {
  3. };
  4. $.validationEngineLanguage = {
  5. newLang: function () {
  6. $.validationEngineLanguage.allRules = {
  7. "required": {// Add your regex rules here, you can take telephone as an example
  8. "regex": "none",
  9. "alertText": "* This field is required",
  10. "alertTextCheckboxMultiple": "* Please select an option",
  11. "alertTextCheckboxe": "* This checkbox is required",
  12. "alertTextDateRange": "* Both date range fields are required"
  13. },
  14. "requiredInFunction": {
  15. "func": function (field, rules, i, options) {
  16. return (field.val() == "test") ? true : false;
  17. },
  18. "alertText": "* Field must equal test"
  19. },
  20. "dateRange": {
  21. "regex": "none",
  22. "alertText": "* Invalid ",
  23. "alertText2": "Date Range"
  24. },
  25. "dateTimeRange": {
  26. "regex": "none",
  27. "alertText": "* Invalid ",
  28. "alertText2": "Date Time Range"
  29. },
  30. "minSize": {
  31. "regex": "none",
  32. "alertText": "* Minimum ",
  33. "alertText2": " characters required"
  34. },
  35. "maxSize": {
  36. "regex": "none",
  37. "alertText": "* Maximum ",
  38. "alertText2": " characters allowed"
  39. },
  40. "groupRequired": {
  41. "regex": "none",
  42. "alertText": "* You must fill one of the following fields",
  43. "alertTextCheckboxMultiple": "* Please select an option",
  44. "alertTextCheckboxe": "* This checkbox is required"
  45. },
  46. "min": {
  47. "regex": "none",
  48. "alertText": "* Minimum value is "
  49. },
  50. "max": {
  51. "regex": "none",
  52. "alertText": "* Maximum value is "
  53. },
  54. "past": {
  55. "regex": "none",
  56. "alertText": "* Date prior to "
  57. },
  58. "future": {
  59. "regex": "none",
  60. "alertText": "* Date past "
  61. },
  62. "maxCheckbox": {
  63. "regex": "none",
  64. "alertText": "* Maximum ",
  65. "alertText2": " options allowed"
  66. },
  67. "minCheckbox": {
  68. "regex": "none",
  69. "alertText": "* Please select ",
  70. "alertText2": " options"
  71. },
  72. "equals": {
  73. "regex": "none",
  74. "alertText": "* Fields do not match"
  75. },
  76. "creditCard": {
  77. "regex": "none",
  78. "alertText": "* Invalid credit card number"
  79. },
  80. "phone": {
  81. // credit: jquery.h5validate.js / orefalo
  82. "regex": /^([\+][0-9]{1,3}([ \.\-])?)?([\(][0-9]{1,6}[\)])?([0-9 \.\-]{1,32})(([A-Za-z \:]{1,11})?[0-9]{1,4}?)$/,
  83. "alertText": "* Invalid phone number"
  84. },
  85. "email": {
  86. // HTML5 compatible email regex ( http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html# e-mail-state-%28type=email%29 )
  87. "regex": /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
  88. "alertText": "* Invalid email address"
  89. },
  90. "strongPass": {
  91. "regex": /^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).*$/g,
  92. "alertText": "* Password must contain at least:<br />- a digit<br />- an uppercase letter<br />- a lowercase letter"
  93. },
  94. "SWPMUserName": {
  95. "regex": /^[a-zA-Z0-9.\-_*@]+$/,
  96. "alertText": "* Invalid Username"
  97. },
  98. "zip": {
  99. "regex": /^\d{5}$|^\d{5}-\d{4}$/,
  100. "alertText": "* Invalid zip format"
  101. },
  102. "integer": {
  103. "regex": /^[\-\+]?\d+$/,
  104. "alertText": "* Not a valid integer"
  105. },
  106. "number": {
  107. // Number, including positive, negative, and floating decimal. credit: orefalo
  108. "regex": /^[\-\+]?((([0-9]{1,3})([,][0-9]{3})*)|([0-9]+))?([\.]([0-9]+))?$/,
  109. "alertText": "* Invalid floating decimal number"
  110. },
  111. "date": {
  112. // Check if date is valid by leap year
  113. "func": function (field) {
  114. var pattern = new RegExp(/^(\d{4})[\/\-\.](0?[1-9]|1[012])[\/\-\.](0?[1-9]|[12][0-9]|3[01])$/);
  115. var match = pattern.exec(field.val());
  116. if (match == null)
  117. return false;
  118. var year = match[1];
  119. var month = match[2] * 1;
  120. var day = match[3] * 1;
  121. var date = new Date(year, month - 1, day); // because months starts from 0.
  122. return (date.getFullYear() == year && date.getMonth() == (month - 1) && date.getDate() == day);
  123. },
  124. "alertText": "* Invalid date, must be in YYYY-MM-DD format"
  125. },
  126. "ipv4": {
  127. "regex": /^((([01]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))[.]){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))$/,
  128. "alertText": "* Invalid IP address"
  129. },
  130. "url": {
  131. "regex": /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i,
  132. "alertText": "* Invalid URL"
  133. },
  134. "onlyNumberSp": {
  135. "regex": /^[0-9\ ]+$/,
  136. "alertText": "* Numbers only"
  137. },
  138. "onlyLetterSp": {
  139. "regex": /^[a-zA-Z\ \']+$/,
  140. "alertText": "* Letters only"
  141. },
  142. "onlyLetterAccentSp": {
  143. "regex": /^[a-z\u00C0-\u017F\ ]+$/i,
  144. "alertText": "* Letters only (accents allowed)"
  145. },
  146. "onlyLetterNumber": {
  147. "regex": /^[0-9a-zA-Z]+$/,
  148. "alertText": "* No special characters allowed"
  149. },
  150. "noapostrophe": {
  151. "regex": /^[^\']*$/,
  152. "alertText": "* Apostrophe character is not allowed"
  153. },
  154. // --- CUSTOM RULES -- Those are specific to the demos, they can be removed or changed to your likings
  155. "ajaxUserCall": {
  156. "url": "ajaxurl",
  157. // you may want to pass extra data on the ajax call
  158. "extraData": "&action=swpm_validate_user_name&nonce="+swpmRegForm.nonce,
  159. "alertTextOk": "* This username is available",
  160. "alertText": "* This user is already taken",
  161. "alertTextLoad": "* Validating, please wait"
  162. },
  163. "ajaxEmailCall": {
  164. "url": "ajaxurl",
  165. // you may want to pass extra data on the ajax call
  166. "extraData": "&action=swpm_validate_email&nonce="+swpmRegForm.nonce,
  167. "alertText": "* This email is already taken",
  168. "alertTextOk": "* This email is available",
  169. "alertTextLoad": "* Validating, please wait"
  170. },
  171. "ajaxUserCallPhp": {
  172. "url": "phpajax/ajaxValidateFieldUser.php",
  173. // you may want to pass extra data on the ajax call
  174. "extraData": "name=eric",
  175. // if you provide an "alertTextOk", it will show as a green prompt when the field validates
  176. "alertTextOk": "* This username is available",
  177. "alertText": "* This user is already taken",
  178. "alertTextLoad": "* Validating, please wait"
  179. },
  180. "ajaxNameCall": {
  181. // remote json service location
  182. "url": "ajaxValidateFieldName",
  183. // error
  184. "alertText": "* This name is already taken",
  185. // if you provide an "alertTextOk", it will show as a green prompt when the field validates
  186. "alertTextOk": "* This name is available",
  187. // speaks by itself
  188. "alertTextLoad": "* Validating, please wait"
  189. },
  190. "ajaxNameCallPhp": {
  191. // remote json service location
  192. "url": "phpajax/ajaxValidateFieldName.php",
  193. // error
  194. "alertText": "* This name is already taken",
  195. // speaks by itself
  196. "alertTextLoad": "* Validating, please wait"
  197. },
  198. "validate2fields": {
  199. "alertText": "* Please input HELLO"
  200. },
  201. //tls warning:homegrown not fielded
  202. "dateFormat": {
  203. "regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$|^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?:(?:0?[1-9]|1[0-2])(\/|-)(?:0?[1-9]|1\d|2[0-8]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(0?2(\/|-)29)(\/|-)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$/,
  204. "alertText": "* Invalid Date"
  205. },
  206. //tls warning:homegrown not fielded
  207. "dateTimeFormat": {
  208. "regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|AM|PM){1}$|^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^((1[012]|0?[1-9]){1}\/(0?[1-9]|[12][0-9]|3[01]){1}\/\d{2,4}\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|AM|PM){1})$/,
  209. "alertText": "* Invalid Date or Date Format",
  210. "alertText2": "Expected Format: ",
  211. "alertText3": "mm/dd/yyyy hh:mm:ss AM|PM or ",
  212. "alertText4": "yyyy-mm-dd hh:mm:ss AM|PM"
  213. }
  214. };
  215. }
  216. };
  217. $.validationEngineLanguage.newLang();
  218. })(jQuery);