博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Bootstrap+PHP表单验证实例
阅读量:7171 次
发布时间:2019-06-29

本文共 3216 字,大约阅读时间需要 10 分钟。

 简单实用的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 ));

本实例下载:

 

posted on
2019-03-06 18:58 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/mrlime/p/10485233.html

你可能感兴趣的文章
敏捷爽畅模型及其演变——Diana Larsen专访
查看>>
苏宁11.11:如何基于异步化打造会员任务平台?
查看>>
十周后,62%的PHP网站将运行在一个不受支持的PHP版本上
查看>>
华为2018:年收入首破千亿美元大关,研发投入过千亿
查看>>
亚马逊继续“激进” :Q3吐出超10倍净利
查看>>
Python数据分析之dataframe索引会这个就行啦
查看>>
TensorFlow 2.0 Alpha 发布,专注于易用性和简单性的提升
查看>>
几个不错的Android开源项目
查看>>
Confluence 6 数据库连接方式
查看>>
Spring+ Spring cloud + SSO单点登录应用认证
查看>>
《认知学习法》学习笔记之“心念一闪,震动十方”
查看>>
你的饭碗还好吗?
查看>>
Jenkins上配置Robot Framework测试邮件通知模板
查看>>
蜗牛爬行日记——记Python2和3的小不同
查看>>
区块链开发公司浅析加速人工智能是否能创新.
查看>>
Matplotlib 3.0 可视化工具强势来袭!
查看>>
数据库的备份
查看>>
11、利用Zabbix监控Web性能和可用性
查看>>
数据库测试
查看>>
shell+Python实现简单的链路监控
查看>>