Advertisement
Guest User

Untitled

a guest
Jun 4th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. $( document ).ready(function() {
  2.  
  3. $.validator.setDefaults({
  4. errorElement: "span",
  5. errorClass: "help-block",
  6. highlight: function (element, errorClass, validClass) {
  7. $(element).closest('.form-group').addClass('has-error has-error has-feedback');
  8. $(element).siblings("span").remove();
  9. $('<span class="glyphicon glyphicon-remove form-control-feedback"></span>').insertAfter(element);
  10. },
  11. unhighlight: function (element, errorClass, validClass) {
  12. $(element).closest('.form-group').removeClass('has-error').addClass('has-success has-feedback');
  13. $(element).siblings("span").remove();
  14. $('<span class="glyphicon glyphicon-ok form-control-feedback"></span>').insertAfter(element);
  15. },
  16. errorPlacement: function (error, element) {
  17. if (element.parent('.input-group').length || element.prop('type') === 'checkbox' || element.prop('type') === 'radio') {
  18. error.insertAfter(element.parent());
  19. } else {
  20. error.insertAfter(element);
  21. }
  22. }
  23. });
  24.  
  25. $.validator.addMethod( "alphanumeric", function( value, element ) {
  26. return this.optional( element ) || /^\w+$/i.test( value );
  27. }, "Letters, numbers, and underscores only please" );
  28.  
  29. $.validator.addMethod( "lettersonly", function( value, element ) {
  30. return this.optional( element ) || /^[a-z]+$/i.test( value );
  31. }, "Letters only please" );
  32.  
  33. $.extend( $.validator.messages, {
  34. required: "Este campo es obligatorio.",
  35. remote: "Por favor, rellena este campo.",
  36. email: "Por favor, escribe una dirección de correo válida.",
  37. url: "Por favor, escribe una URL válida.",
  38. date: "Por favor, escribe una fecha válida.",
  39. dateISO: "Por favor, escribe una fecha (ISO) válida.",
  40. number: "Por favor, escribe un número válido.",
  41. digits: "Por favor, escribe sólo dígitos.",
  42. creditcard: "Por favor, escribe un número de tarjeta válido.",
  43. equalTo: "Por favor, escribe el mismo password de nuevo.",
  44. extension: "Por favor, escribe un valor con una extensión aceptada.",
  45. maxlength: $.validator.format( "Por favor, no escribas más de {0} caracteres." ),
  46. minlength: $.validator.format( "Por favor, no escribas menos de {0} caracteres." ),
  47. rangelength: $.validator.format( "Por favor, escribe un valor entre {0} y {1} caracteres." ),
  48. range: $.validator.format( "Por favor, escribe un valor entre {0} y {1}." ),
  49. max: $.validator.format( "Por favor, escribe un valor menor o igual a {0}." ),
  50. min: $.validator.format( "Por favor, escribe un valor mayor o igual a {0}." ),
  51. nifES: "Por favor, escribe un NIF válido.",
  52. nieES: "Por favor, escribe un NIE válido.",
  53. cifES: "Por favor, escribe un CIF válido.",
  54. alphanumeric: "Por favor, escribe solo letras, numeros y guiones bajos.",
  55. lettersonly: "Por favor, escribe solo letras A-Z."
  56. } );
  57.  
  58.  
  59. $("#registrationForm").validate({
  60. rules: {
  61. username: {
  62. required: true,
  63. minlength: 5,
  64. maxlength: 20,
  65. alphanumeric: true
  66. },
  67. password: {
  68. required: true,
  69. minlength: 6,
  70. maxlength: 25
  71. },
  72. confirmPassword: {
  73. required: true,
  74. minlength: 5,
  75. maxlength: 25,
  76. equalTo: "#password"
  77. },
  78. email: {
  79. required: true,
  80. minlength: 5,
  81. maxlength: 100,
  82. email: true
  83. },
  84. firstname: {
  85. required: true,
  86. minlength: 1,
  87. maxlength: 100,
  88. lettersonly: true
  89. },
  90. lastname: {
  91. required: true,
  92. minlength: 1,
  93. maxlength: 100,
  94. lettersonly: true
  95. }
  96. }
  97. });
  98. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement