selector.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>BootstrapValidator demo</title>
  5. <link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css"/>
  6. <link rel="stylesheet" href="../dist/css/bootstrapValidator.css"/>
  7. <script type="text/javascript" src="../vendor/jquery/jquery-1.10.2.min.js"></script>
  8. <script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script>
  9. <script type="text/javascript" src="../dist/js/bootstrapValidator.js"></script>
  10. </head>
  11. <body>
  12. <div class="container">
  13. <div class="row">
  14. <section>
  15. <div class="col-lg-8 col-lg-offset-2">
  16. <div class="page-header">
  17. <h2>Credit card information</h2>
  18. </div>
  19. <form id="paymentForm" method="post" class="form-horizontal" action="target.php">
  20. <div class="form-group">
  21. <label class="col-lg-3 control-label">Credit card number</label>
  22. <div class="col-lg-5">
  23. <input type="text" class="form-control" id="ccNumber" />
  24. </div>
  25. </div>
  26. <div class="form-group">
  27. <label class="col-lg-3 control-label">Expiration</label>
  28. <div class="col-lg-4">
  29. <input type="text" class="form-control" placeholder="Month" data-stripe="exp-month" />
  30. </div>
  31. <div class="col-lg-4">
  32. <input type="text" class="form-control" placeholder="Year" data-stripe="exp-year" />
  33. </div>
  34. </div>
  35. <div class="form-group">
  36. <label class="col-lg-3 control-label">CVV</label>
  37. <div class="col-lg-2">
  38. <input type="text" class="form-control cvvNumber" />
  39. </div>
  40. </div>
  41. <div class="form-group">
  42. <div class="col-lg-9 col-lg-offset-3">
  43. <button type="submit" class="btn btn-primary">Pay</button>
  44. </div>
  45. </div>
  46. </form>
  47. </div>
  48. </section>
  49. </div>
  50. </div>
  51. <script type="text/javascript">
  52. $(document).ready(function() {
  53. $('#paymentForm').bootstrapValidator({
  54. feedbackIcons: {
  55. valid: 'glyphicon glyphicon-ok',
  56. invalid: 'glyphicon glyphicon-remove',
  57. validating: 'glyphicon glyphicon-refresh'
  58. },
  59. fields: {
  60. ccNumber: {
  61. selector: '#ccNumber',
  62. validators: {
  63. notEmpty: {
  64. message: 'The credit card number is required'
  65. },
  66. creditCard: {
  67. message: 'The credit card number is not valid'
  68. }
  69. }
  70. },
  71. expMonth: {
  72. selector: '[data-stripe="exp-month"]',
  73. validators: {
  74. notEmpty: {
  75. message: 'The expiration month is required'
  76. },
  77. digits: {
  78. message: 'The expiration month can contain digits only'
  79. },
  80. callback: {
  81. message: 'Expired',
  82. callback: function(value, validator) {
  83. value = parseInt(value, 10);
  84. var currentMonth = new Date().getMonth() + 1;
  85. return (value <= 12 && value >= currentMonth);
  86. }
  87. }
  88. }
  89. },
  90. expYear: {
  91. selector: '[data-stripe="exp-year"]',
  92. validators: {
  93. notEmpty: {
  94. message: 'The expiration year is required'
  95. },
  96. digits: {
  97. message: 'The expiration year can contain digits only'
  98. },
  99. callback: {
  100. message: 'Expired',
  101. callback: function(value, validator) {
  102. value = parseInt(value, 10);
  103. var currentYear = new Date().getFullYear();
  104. return (value >= currentYear && value <= currentYear + 100);
  105. }
  106. }
  107. }
  108. },
  109. cvvNumber: {
  110. selector: '.cvvNumber',
  111. validators: {
  112. notEmpty: {
  113. message: 'The CVV number is required'
  114. },
  115. cvv: {
  116. message: 'The value is not a valid CVV',
  117. creditCardField: 'ccNumber'
  118. }
  119. }
  120. }
  121. }
  122. });
  123. });
  124. </script>
  125. </body>
  126. </html>