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
最近更新
- 响应式全屏手风琴菜单,同时支持垂直方...
- 分组select选择器,支持多选和单...
- jQuery时间日期选择器代码日历插...
- Select 选择器 可以清空的单选...
- jQuery json 无刷新翻页 ...
- 纯css3带倒影效果的图片翻转特效
我爱薅羊毛
点击最多
广告赞助
相关文章
- 美化input radio select等输入框,...
- select 下拉框多选,用select代替che...
- jQuery下拉多选插件 下拉框复选 包括全选
- radio单选框彩色,自定义边框,圆点颜色和大小
- 自定义checkbox和radio样式 圆形方形...
- select下拉菜单带图片