vue实现密码的表单验证~(旧密码,新密码,重复新密码)
2018-05-09 12:26
791 查看
1. template中
<Button @click="changePsw">修改密码</Button> <Modal v-model="changePswData.changePswModel" :closable="false" :mask-closable="false" title="修改密码" @on-ok="changePswOk" @on-cancel="changePswCancel"> <div style="margin-bottom: 5px;"> <p style="display: inline-block; width: 100px;">原密码:</p> <Input type="password" :maxlength="20" v-model="changePswData.oldPsw" placeholder="请输入原密码..." style="width: 300px" @on-blur="oldPswValid" @on-focus="oldPswValid_focus"></Input> <p style="display: inline; color: red;margin-left: 110px;" :style="{display: changePswData.oldPsw_pswLog_noBlank_Flag}">{{ changePswData.oldPsw_pswLog_noBlank }}</p> </div> <div style="margin-bottom: 5px;"> <p style="display: inline-block; width: 100px;">新密码:</p> <Input type="password" :maxlength="20" v-model="changePswData.newPsw" placeholder="请输入新密码..." style="width: 300px" @on-blur="newPswValid" @on-focus="newPswValid_focus"></Input> <p style="display: inline; color: red;margin-left: 110px;" :style="{display: changePswData.newPsw_pswLog_noBlank_Flag}">{{ changePswData.newPsw_pswLog_noBlank }}</p> <p style="display: inline; color: red;margin-left: 110px;" :style="{display: changePswData.pswLog_pattern_Flag}">{{ changePswData.pswLog_pattern }}</p> </div> <div> <p style="display: inline-block; width: 100px;">重复新密码:</p> <Input type="password" :maxlength="20" v-model="changePswData.againNewPsw" placeholder="请再输入一次新密码..." style="width: 300px" @on-blur="againNewPswValid" @on-focus="againNewPswValid_focus"></Input> <p style="display: inline; color: red;margin-left: 110px;" :style="{display: changePswData.againNewPsw_pswLog_noBlank_Flag}">{{ changePswData.againNewPsw_pswLog_noBlank }}</p> <p style="display: inline; color: red;margin-left: 110px;" :style="{display: changePswData.pswLog_equality_Flag}">{{ changePswData.pswLog_equality }}</p> </div> </Modal>
2. data中
changePswData: { changePswModel: false, oldPsw: '', oldPsw_pswLog_noBlank: '密码不能为空,请重新输入', oldPsw_pswLog_noBlank_Flag: 'none', newPsw: '', newPsw_pswLog_noBlank: '密码不能为空,请重新输入', newPsw_pswLog_noBlank_Flag: 'none', pswLog_pattern: '密码由5-20位数字字母组成,请重新输入', pswLog_pattern_Flag: 'none', againNewPsw: '', againNewPsw_pswLog_noBlank: '密码不能为空,请重新输入', againNewPsw_pswLog_noBlank_Flag: 'none', pswLog_equality: '两次输入密码不相等,请重新输入', pswLog_equality_Flag: 'none' }
3.methods中
// 打开Model框 changePsw: function () { this.changePswModel = true; }, // 验证输入框 oldPswValid: function() { console.log(this.changePswData.oldPsw) if(this.changePswData.oldPsw != ''){ this.changePswData.oldPsw_pswLog_noBlank_Flag = 'none' }else{ this.changePswData.oldPsw_pswLog_noBlank_Flag = 'block' } }, oldPswValid_focus: function() { this.changePswData.oldPsw_pswLog_noBlank_Flag = 'none' }, newPswValid: function() { console.log(this.changePswData.newPsw) if(this.changePswData.newPsw != ''){ this.changePswData.newPsw_pswLog_noBlank_Flag = 'none'; let pattern = /^[a-zA-Z0-9]{6,20}$/; if(!pattern.test(this.changePswData.newPsw)){ this.changePswData.pswLog_pattern_Flag = 'block'; }else{ this.changePswData.pswLog_pattern_Flag = 'none'; } }else{ this.changePswData.newPsw_pswLog_noBlank_Flag = 'block' } }, newPswValid_focus: function() { this.changePswData.newPsw_pswLog_noBlank_Flag = 'none'; this.changePswData.pswLog_pattern_Flag = 'none'; }, againNewPswValid: function() { console.log(this.changePswData.againNewPsw) if(this.changePswData.againNewPsw != ''){ this.changePswData.againNewPsw_pswLog_noBlank_Flag = 'none'; if(this.changePswData.againNewPsw != this.changePswData.newPsw){ this.changePswData.pswLog_equality_Flag = 'block' }else{ this.changePswData.pswLog_equality_Flag = 'none' } }else{ this.changePswData.againNewPsw_pswLog_noBlank_Flag = 'block' } }, againNewPswValid_focus: function() { this.changePswData.againNewPsw_pswLog_noBlank_Flag = 'none'; this.changePswData.pswLog_equality_Flag = 'none' }, // 修改密码 changePswOk: function () { let self = this; console.log(self.validPsw()) if(self.validPsw() == 1){ axios.post('#', { password: self.changePswData.oldPsw, newPassword: self.changePswData.newPsw }).then(function (response) { let data = response.data.data; let status = response.data.status; if(status == '0'){ self.$Message.success(data); } }).catch(function (error) { self.$Message.error('修改密码失败,请重新修改!'); }) }else{ self.$Message.error('修改密码失败,请重新修改!'); } }, changePswCancel: function () { }
相关文章推荐
- angularjs 表单密码验证自定义指令实现代码
- vue+vue-validator 表单验证功能的实现代码
- 在jsp界面实现对表单用户名、密码不能为空的验证代码
- vue项目实现表单登录页保存账号和密码到cookie功能
- vue项目实现表单登录页保存账号和密码到cookie功能
- Session实现表单重复提交验证
- 利用hashtable模拟实现权限验证(同map思想-->只能有一个用户名,可重复密码)以及增删查改操作
- vue+element-ui集成随机验证码+用户名+密码的form表单验证功能
- jQuery实现验证表单密码一致性及正则表达式验证邮箱、手机号的方法
- ExtJS中表单验证使用自定义vtype(两次输入密码重复)示例
- 使用Spring AOP注解方式实现表单重复提交验证功能
- 浏览器表单验证用户名密码非空的js实现
- bootstrap框架下实现表单提交数据重复验证
- Laravel 中使用 Vue.js 实现基于 Ajax 的表单提交错误验证操作
- BootStrap+Mybatis框架下实现表单提交数据重复验证
- php实现表单密码验证的代码实例
- PHP实现防止表单重复提交功能【基于token验证】
- vue动态绑定组件子父组件多表单验证功能的实现代码
- vue 使用 vuelidate 实现表单验证
- 实现带样式的表单验证:用户名、密码验证