message.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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="page-header">
  15. <h1>Use error message that is returned from remote/callback validator</h1>
  16. </div>
  17. <div class="col-lg-8 col-lg-offset-2">
  18. <form id="defaultForm" method="post" class="form-horizontal" action="target.php">
  19. <div class="form-group">
  20. <label class="col-lg-3 control-label">Username</label>
  21. <div class="col-lg-5">
  22. <input type="text" class="form-control" name="username" autocomplete="off" />
  23. </div>
  24. </div>
  25. <div class="form-group">
  26. <label class="col-lg-3 control-label">Email address</label>
  27. <div class="col-lg-5">
  28. <input type="text" class="form-control" name="email" autocomplete="off" />
  29. </div>
  30. </div>
  31. <div class="form-group">
  32. <label class="col-lg-3 control-label">Password</label>
  33. <div class="col-lg-5">
  34. <input type="password" class="form-control" name="password" />
  35. </div>
  36. </div>
  37. <div class="form-group">
  38. <div class="col-lg-9 col-lg-offset-3">
  39. <button type="submit" class="btn btn-primary">Submit</button>
  40. </div>
  41. </div>
  42. </form>
  43. </div>
  44. </div>
  45. <script type="text/javascript">
  46. $(document).ready(function() {
  47. $('#defaultForm').bootstrapValidator({
  48. message: 'This value is not valid',
  49. feedbackIcons: {
  50. valid: 'glyphicon glyphicon-ok',
  51. invalid: 'glyphicon glyphicon-remove',
  52. validating: 'glyphicon glyphicon-refresh'
  53. },
  54. fields: {
  55. username: {
  56. message: 'The username is not valid',
  57. validators: {
  58. notEmpty: {
  59. message: 'The username is required and can\'t be empty'
  60. },
  61. remote: {
  62. url: 'remote2.php'
  63. },
  64. different: {
  65. field: 'password',
  66. message: 'The username and password can\'t be the same as each other'
  67. }
  68. }
  69. },
  70. email: {
  71. validators: {
  72. notEmpty: {
  73. message: 'The email address is required and can\'t be empty'
  74. },
  75. emailAddress: {
  76. message: 'The input is not a valid email address'
  77. },
  78. remote: {
  79. url: 'remote2.php'
  80. }
  81. }
  82. },
  83. password: {
  84. validators: {
  85. notEmpty: {
  86. message: 'The password is required and can\'t be empty'
  87. },
  88. different: {
  89. field: 'username',
  90. message: 'The password can\'t be the same as username'
  91. },
  92. callback: {
  93. callback: function(value, validator) {
  94. // Check the password strength
  95. if (value.length < 6) {
  96. return {
  97. valid: false,
  98. message: 'The password must be more than 6 characters'
  99. }
  100. }
  101. if (value === value.toLowerCase()) {
  102. return {
  103. valid: false,
  104. message: 'The password must contain at least one upper case character'
  105. }
  106. }
  107. if (value === value.toUpperCase()) {
  108. return {
  109. valid: false,
  110. message: 'The password must contain at least one lower case character'
  111. }
  112. }
  113. if (value.search(/[0-9]/) < 0) {
  114. return {
  115. valid: false,
  116. message: 'The password must contain at least one digit'
  117. }
  118. }
  119. return true;
  120. }
  121. }
  122. }
  123. }
  124. }
  125. });
  126. });
  127. </script>
  128. </body>
  129. </html>