PHP验证器类Validator,输入数据提交验证
XML/HTML Code
- <div class="row main">
- <div class="col-md-12">
- <div class="row" style="margin: 30px;">
- <div class="col-md-6 col-sm-12">
- <form class="form-inline" rel="1">
- <div class="form-group">
- <label for="">输入数字</label>
- <input type="text" class="form-control" placeholder="必须输入数字">
- </div>
- <button type="submit" class="btn btn-default">验证</button>
- </form>
- </div>
- <div class="col-md-6 col-sm-12">
- <form class="form-inline" rel="2">
- <div class="form-group">
- <label for="">输入出生日期</label>
- <input type="text" class="form-control" placeholder="1990-12-30">
- </div>
- <button type="submit" class="btn btn-default">验证</button>
- </form>
- </div>
- <div class="col-md-6 col-sm-12">
- <form class="form-inline" rel="3">
- <div class="form-group">
- <label for="">输入3-8位用户名</label>
- <input type="text" class="form-control" placeholder="alam">
- </div>
- <button type="submit" class="btn btn-default">验证</button>
- </form>
- </div>
- <div class="col-md-6 col-sm-12">
- <form class="form-inline" rel="4">
- <div class="form-group">
- <label for="">输入Json数据</label>
- <input type="text" class="form-control" placeholder='{"foo":"bar"}'>
- </div>
- <button type="submit" class="btn btn-default">验证</button>
- </form>
- </div>
- <div class="col-md-6 col-sm-12">
- <form class="form-inline" rel="5">
- <div class="form-group">
- <label for="">输入Email</label>
- <input type="text" class="form-control" placeholder="abc@example.com">
- </div>
- <button type="submit" class="btn btn-default">验证</button>
- </form>
- </div>
- <div class="col-md-6 col-sm-12">
- <form class="form-inline" rel="6">
- <div class="form-group">
- <label for="">输入网址</label>
- <input type="text" class="form-control" placeholder="https://www.helloweba.net">
- </div>
- <button type="submit" class="btn btn-default">验证</button>
- </form>
- </div>
- </div>
- </div>
- </div>
JavaScript Code
- <script>
- $(document).on('submit', 'form', function(event) {
- event.preventDefault();
- var ipt_val = $(this).find('input').val();
- if (ipt_val == '') {
- alert('不能为空!');
- return false;
- }
- var rel = $(this).attr('rel');
- $.post('verify.php', {value: ipt_val, mod: rel}, function(res, textStatus, xhr) {
- if (res == 1) {
- alert('输入正确!');
- } else {
- alert('输入错误!');
- }
- });
- });
- </script>
原文地址:http://www.freejs.net/article_biaodan_709.html