Bootstrap+PHP表单验证实例

简单实用的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表单验证实例的更多相关文章
- jQuery-easyui和validate表单验证实例
jQuery EasyUI 表单 - 表单验证插件validatebox 使用时需要向页面引入两个css文件如下: <link rel="stylesheet" href=& ...
- jquery-4 完整表单验证实例
jquery-4 完整表单验证实例 一.总结 一句话总结:在form的jquery对象中返回false即可终止表单提交. 1.验证的显示错误消息如何布局? 开始时隐藏,出现错误后显示 10 .erro ...
- HTML5 web Form表单验证实例
HTML5 web Form 的开发实例! index.html <!DOCTYPE html> <html> <head> <meta charset=&q ...
- bootstrap学习起步篇:初识bootstrap之表单验证(二)
学习bootstrap是个过程,它提供给我们的文档上有很详细的说明.包括常用的栅栏布局.页面元素等,这里就不啰嗦了,今天,我就来说下结合jquery的表单验证. 最开始不借助插件,我们需要自己去编写验 ...
- 【前端_js】Bootstrap之表单验证
Bootstrap表单验证插件bootstrapValidator使用方法整理 BootstrapValidator 表单验证超详细教程
- angular表单验证实例----可用的代码
前段时间,公司做一个单页面,就是一个表单验证,早开始在菜鸟教程上关注了angular,所以下派上用场了 angular里面对于表单验证,设置了很多指令. 也就是说不用自己写一些逻辑,直接绑定指令就行. ...
- jQuery常用插件与jQuery使用validation插件实现表单验证实例
jQuery常用插件 1,jQuery特别容易扩展,开发者可以基于jQuery开发一些扩展动能 2,插件:http://plugins.jquery.com 3,超厉害的插件:validation . ...
- vue 表单验证实例
1.注册 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- Yii 框架表单验证---实例
随机推荐
- golang初识5 - interface
1. interface-new (1) abstract format: type abstractName interface { method_name1 [return_type] } (2) ...
- iis7.5 配置伪静态
1)首先新建一个应用程序池,名称任意,比如:nettest,托管管道模式先暂时设置为集成模式,等下面的一系列设置完成之后再设置成经典模式: 2)部署好站点,并将此站点的应用程序池设置为nettest; ...
- Docker笔记——jdk镜像制作
openjdk镜像依赖如下: openjdk:8-jdk -> buildpack-deps:jessie-scm -> buildpack-deps:jessie-curl -> ...
- Shell:常用+好用命令
1.#删除15天前的数据 find /usr/local/chen/backup/ -mtime +15 -exec rm -f {} \; 2.release=`echo $name | cut - ...
- py库:os、shutil、pathlib
https://www.cnblogs.com/MnCu8261/p/5494807.html shutil模块 http://blog.csdn.net/rozol/article/details/ ...
- C#通过COM组件调用IDL的pro程序
如果在“COM_IDL_connectLib.COM_IDL_connect oComIDL = new COM_IDL_connectLib.COM_IDL_connect();”步骤提示“...8 ...
- js 字符串操作方法
1.字符串转换 你可以将任何类型的数据都转换为字符串,你可以用下面三种方法的任何一种: 1 2 var num= 19; // 19 var myStr = num.toString(); // &q ...
- Caused by: javax.persistence.NonUniqueResultException: result returns more than one elements
Caused by: javax.persistence.NonUniqueResultException: result returns more than one elements at org. ...
- 【转】STM32 不占用定时器(包括SysTick)实现精确延时(巧用DWT)
/** ****************************************************************** * file core_delay.c * author ...
- mysql for循环存储过程
DROP PROCEDURE IF EXISTS test_insert; DELIMITER ;; CREATE PROCEDURE test_insert () BEGIN DECLARE i i ...