简单的表单验证
XML/HTML Code
- <form class="form-example" novalidate>
- <div class="form-row">
- <label>First name: <input type="text" name="words" data-validation-cfg="letters_special" required class="form-control">
- </label>
- </div>
- <div class="form-row">
- <label>Digits:<input type="text" name="only-digits" data-validation-cfg="digits_only" required value="" class="form-control">
- </label>
- </div>
- <div class="form-row">
- <label>Digits with separtors:<input type="text" name="only-digits" data-validation-cfg="digits_and_separators_only,required" value="" class="form-control">
- </label>
- </div>
- <div class="form-row-submit form-row">
- <button type="submit" class="btn btn-primary">submit</button>
- </div>
- </form>
JavaScript Code
- <script>
- 'use strict';
- (function ($, window, document, undefined) {
- $(function () {
- function initDeRegexValidation() {
- $('.form-example').deRegexValidation({
- preventSubmitOnInvalid: true,
- disableFormOnInvalid: true,
- validateRequiredFields: true,
- });
- }
- initDeRegexValidation();
- });
- })(jQuery, window, document);
- </script>
原文地址:http://www.freejs.net/article_biaodan_823.html