简单实用的Bootstrap+PHP表单验证实例,非常适合初学者及js不熟悉者,还有ajax远程验证

js验证表单

 1 $(document).ready(function() {
 2     $('#defaultForm')
 3             .bootstrapValidator({
 4                 message: 'This value is not valid',
 5                 feedbackIcons: {
 6                     valid: 'glyphicon glyphicon-ok',
 7                     invalid: 'glyphicon glyphicon-remove',
 8                     validating: 'glyphicon glyphicon-refresh'
 9                 },
10                 fields: {
11                     username: {
12                         message: 'The username is not valid',
13                         validators: {
14                             notEmpty: {
15                                 message: 'The username is required and can\'t be empty'
16                             },
17                             stringLength: {
18                                 min: 6,
19                                 max: 30,
20                                 message: 'The username must be more than 6 and less than 30 characters long'
21                             },
22                             /*remote: {
23                              url: 'remote.php',
24                              message: 'The username is not available'
25                              },*/
26                             regexp: {
27                                 regexp: /^[a-zA-Z0-9_\.]+$/,
28                                 message: 'The username can only consist of alphabetical, number, dot and underscore'
29                             }
30                         }
31                     },
32                     email: {
33                         validators: {
34                             notEmpty: {
35                                 message: 'The email address is required and can\'t be empty'
36                             },
37                             emailAddress: {
38                                 message: 'The input is not a valid email address'
39                             }
40                         }
41                     },
42                     password: {
43                         validators: {
44                             notEmpty: {
45                                 message: 'The password is required and can\'t be empty'
46                             }
47                         }
48                     }
49                 }
50             })
51             .on('success.form.bv', function(e) {
52                 // Prevent form submission
53                 e.preventDefault();
54
55                 // Get the form instance
56                 var $form = $(e.target);
57
58                 // Get the BootstrapValidator instance
59                 var bv = $form.data('bootstrapValidator');
60
61                 // Use Ajax to submit form data
62                 $.post($form.attr('action'), $form.serialize(), function(result) {
63                     console.log(result);
64                 }, 'json');
65             });
66 });

PHP远程验证用户名

1 $userName = $_POST['username'];
2
3 echo json_encode(array(
4     'message' => sprintf('Welcome %s', $userName),
5 ));

本实例下载:https://www.sucaihuo.com/php/1814.html

Bootstrap+PHP表单验证实例的更多相关文章

  1. jQuery-easyui和validate表单验证实例

    jQuery EasyUI 表单 - 表单验证插件validatebox 使用时需要向页面引入两个css文件如下: <link rel="stylesheet" href=& ...

  2. jquery-4 完整表单验证实例

    jquery-4 完整表单验证实例 一.总结 一句话总结:在form的jquery对象中返回false即可终止表单提交. 1.验证的显示错误消息如何布局? 开始时隐藏,出现错误后显示 10 .erro ...

  3. HTML5 web Form表单验证实例

    HTML5 web Form 的开发实例! index.html <!DOCTYPE html> <html> <head> <meta charset=&q ...

  4. bootstrap学习起步篇:初识bootstrap之表单验证(二)

    学习bootstrap是个过程,它提供给我们的文档上有很详细的说明.包括常用的栅栏布局.页面元素等,这里就不啰嗦了,今天,我就来说下结合jquery的表单验证. 最开始不借助插件,我们需要自己去编写验 ...

  5. 【前端_js】Bootstrap之表单验证

    Bootstrap表单验证插件bootstrapValidator使用方法整理 BootstrapValidator 表单验证超详细教程    

  6. angular表单验证实例----可用的代码

    前段时间,公司做一个单页面,就是一个表单验证,早开始在菜鸟教程上关注了angular,所以下派上用场了 angular里面对于表单验证,设置了很多指令. 也就是说不用自己写一些逻辑,直接绑定指令就行. ...

  7. jQuery常用插件与jQuery使用validation插件实现表单验证实例

    jQuery常用插件 1,jQuery特别容易扩展,开发者可以基于jQuery开发一些扩展动能 2,插件:http://plugins.jquery.com 3,超厉害的插件:validation . ...

  8. vue 表单验证实例

    1.注册 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  9. Yii 框架表单验证---实例

随机推荐

  1. docker开启远程访问

    作者:zqifa 出处:http://www.cnblogs.com/zqifa/ 默认情况下,Docker守护进程Unix socket(/var/run/docker.sock)来进行本地进程通信 ...

  2. 自制按钮图标的两种方法: image sprite和svg字体文件

    用image sprite和svg字体文件这两种方法,都能够极大地减少小图形文件的数量, 从而减少服务器请求和带宽需求.提高网页的响应速度. 一.建立SVG字体文件 iconmoon 是一个在线工具, ...

  3. Linq to SQL -- Join

    Join操作 适用场景:在我们表关系中有一对一关系,一对多关系,多对多关系等.对各个表之间的关系,就用这些实现对多个表的操作. 说明:在Join操作中,分别为Join(Join查询), SelectM ...

  4. Postman Could not get any response

    在使用postman时遇到的小问题,记录一下: 报错信息如下: Could not get any response There was an error connecting to https:// ...

  5. Day71Django基础

    Django框架基础一 python中的web框架    a:socket    b:路由跟视图函数匹配关系    c:模板渲染    django:  a: 用了别人的wsgiref   b:自己写 ...

  6. mint linux 18.3 遇到“已安装的 post-installation 脚本 返回了错误号 127 ”问题的解决

    From https://blog.csdn.net/ropai/article/details/27171687 ubuntu 14.04遇到“已安装的 post-installation 脚本 返 ...

  7. ASP.NET MVC 3 Application Upgrader

    ASP.NET MVC 3 Application Upgrader: http://aspnet.codeplex.com/releases/view/59008

  8. Eclipse导入文件识别不了jsp怎么办

    1.在出现错误代码页开始处加上<%@ page import="java.util.*"%>,把包引进来2.然后右击项目,依次选择Properties->Java ...

  9. Flask框架里的cookie和session

    # -*- encoding: utf-8 -*- #cookie 相关的操作,依赖与make_response库,调用cookie依赖request模块 from flask import Flas ...

  10. vim 批量替换使用说明

    基本语法: :[addr]s/源字符串/目的字符串/[option] 全局替换命令: :%s/源字符串/目的字符串/g [addr] 表示检索范围,省略时表示当前行. "1,20" ...