file.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.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. <div class="col-lg-8 col-lg-offset-2">
  15. <div class="page-header">
  16. <h2>File validator</h2>
  17. </div>
  18. <form id="defaultForm" method="post" class="form-horizontal">
  19. <div class="form-group">
  20. <label class="col-lg-4 control-label">File</label>
  21. <div class="col-lg-7">
  22. <input type="file" class="form-control" name="firstFile" />
  23. <span class="help-block">Choose a pdf file.</span>
  24. </div>
  25. </div>
  26. <div class="form-group">
  27. <label class="col-lg-4 control-label">File with min size</label>
  28. <div class="col-lg-7">
  29. <input type="file" class="form-control" name="secondFile" />
  30. <span class="help-block">Choose a pdf file with a size more than 1M.</span>
  31. </div>
  32. </div>
  33. <div class="form-group">
  34. <label class="col-lg-4 control-label">File with max size</label>
  35. <div class="col-lg-7">
  36. <input type="file" class="form-control" name="thirdFile" />
  37. <span class="help-block">Choose a pdf file with a size less than 10M.</span>
  38. </div>
  39. </div>
  40. <div class="form-group">
  41. <label class="col-lg-4 control-label">File with min and max size</label>
  42. <div class="col-lg-7">
  43. <input type="file" class="form-control" name="fourthFile" />
  44. <span class="help-block">Choose a pdf file with a size between 1M and 10M.</span>
  45. </div>
  46. </div>
  47. <div class="form-group">
  48. <div class="col-lg-9 col-lg-offset-4">
  49. <button type="submit" class="btn btn-primary" name="filevalidate" value="Validate">Validate</button>
  50. </div>
  51. </div>
  52. </form>
  53. </div>
  54. </div>
  55. </div>
  56. <script type="text/javascript">
  57. $(document).ready(function() {
  58. $('#defaultForm').bootstrapValidator({
  59. feedbackIcons: {
  60. valid: 'glyphicon glyphicon-ok',
  61. invalid: 'glyphicon glyphicon-remove',
  62. validating: 'glyphicon glyphicon-refresh'
  63. },
  64. fields: {
  65. firstFile: {
  66. validators: {
  67. file: {
  68. extension: 'pdf',
  69. type: 'application/pdf',
  70. message: 'Please choose a pdf file.'
  71. }
  72. }
  73. },
  74. secondFile: {
  75. validators: {
  76. file: {
  77. extension: 'pdf',
  78. type: 'application/pdf',
  79. minSize: 1024*1024,
  80. message: 'Please choose a pdf file with a size more than 1M.'
  81. }
  82. }
  83. },
  84. thirdFile: {
  85. validators: {
  86. file: {
  87. extension: 'pdf',
  88. type: 'application/pdf',
  89. maxSize: 10*1024*1024,
  90. message: 'Please choose a pdf file with a size less than 10M.'
  91. }
  92. }
  93. },
  94. fourthFile: {
  95. validators: {
  96. file: {
  97. extension: 'pdf',
  98. type: 'application/pdf',
  99. minSize: 1024*1024,
  100. maxSize: 10*1024*1024,
  101. message: 'Please choose a pdf file with a size between 1M and 10M.'
  102. }
  103. }
  104. }
  105. }
  106. })
  107. .on('success.form.bv', function(e) {
  108. e.preventDefault();
  109. $('#defaultForm').data('bootstrapValidator').disableSubmitButtons(true);
  110. });
  111. });
  112. </script>
  113. </body>
  114. </html>