VUE-表单验证
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<script src="vue.js"></script>
</head>
<body>
<div id="app">
<form>
用户名 <input type="text" name="username" v-model="username">
手机号 <input type="text" name="mobile" v-model="mobile">
密码 <input type="password" name="password" v-model="password">
<button type="button" @click="login" >登录</button>
</form>
<p v-for="(v,k) in err_arr">
{{v}}
</p>
</div>
</body>
</html>
<script> new Vue({
el:"#app",
data:{
auth_user:"zhangsan123",
auth_pass:"123456",
auth_mobile:"18518505221",
username:'',
password:'',
mobile:'',
err_arr:[]
},
methods:{
login(){
if(this.validate()){
alert("登录成功");
}
},
//验证器
validate(){
this.err_arr = [];
if(this.username == ""){
this.err_arr.push('用户名不能为空');
return false;
}
var reg_user = /^[a-zA-Z\u4e00-\u9fa5]\w{6,16}$/;
if(!reg_user.test(this.username)){
this.err_arr.push('用户名格式不正确');
return false;
} if(this.mobile == ""){
this.err_arr.push('手机号不能为空');
return false;
}
var reg_mobile = /^1[35678]\d{9}$/;
if(!reg_mobile.test(this.mobile)){
this.err_arr.push('手机号格式不正确');
return false;
} if(this.password == ""){
this.err_arr.push('密码不能为空');
return false;
}
var reg_pass = /^\w{6,15}$/;
if(!reg_pass.test(this.password)){
this.err_arr.push('密码格式不正确');
return false;
} if(this.auth_mobile == this.mobile && this.auth_pass == this.password && this.auth_user == this.username){
this.err_arr = [];
return true;
}else {
this.err_arr.push('账号或者密码出错');
return false;
} }
} });
</script>
VUE-表单验证的更多相关文章
- vue表单验证--veevalidate使用教程
vue表单验证----vee-validate使用教程 官网:https://baianat.github.io/vee-validate/ 一.安装 npm install vee-validate ...
- 写一个简单易用可扩展vue表单验证插件(vue-validate-easy)
写一个vue表单验证插件(vue-validate-easy) 需求 目标:简单易用可扩展 如何简单 开发者要做的 写了一个表单,指定一个name,指定其验证规则. 调用提交表单方法,可以获取验证成功 ...
- vue 表单验证实例
1.注册 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- vue表单验证:vee-validate中文提示
官方文档:https://baianat.github.io/vee-validate/guide/ vee-validate可用于vue项目中进行表单验证,使用方法在官方API上都可以查到: 使用过 ...
- Vue表单验证插件的制作过程
一.表单验证模块的构成 任何表单验证模块都是由 配置――校验――报错――取值 这几部分构成的. 配置: 配置规则 和配置报错,以及优先级 校验: 有在 change 事件校验, 在点击提交按钮的时候校 ...
- Vue 表单验证插件
verify github:https://github.com/liuyinglong/verifynpm:https://www.npmjs.com/package/vue-verify-plug ...
- vue 表单验证省市县三联动
<el-col :span="24"> <el-form-item label="所在地区" prop="region" ...
- vue表单验证不通过,依然能执行点击事件里面的代码?
遇到的问题:表单提交的时候,写了rules,明明验证不通过依然执行了点击事件里面的代码. 这个验证有什么用? 后来 我看elementUI组件才发现,我漏写了几行代码. methods里面这样写 完美 ...
- 一个不错的vue表单验证插件
github文档 用着不错,官方的文档例子很简单 <body> <div id="app"> <validator name="valida ...
- vue 表单 验证 async-validator
1.使用插件async-validator async-validator 地址:https://github.com/yiminghe/async-validator 2.示例(vue+elemen ...
随机推荐
- AT2346 [ARC070B] No Need
这里介绍几种做法. 解法一 首先可以转化一下题意,\(\forall i\) 如果 \(i\) 不是可有可无的当且仅当不用 \(i\) 能拼出 \([K - a_i, K)\) 中的数. 基于观察可以 ...
- 汉字编码(【Unicode】 【UTF-8】 【Unicode与UTF-8之间的转换】 【汉字 Unicode 编码范围】【中文标点Unicode码】【GBK编码】【批量获取汉字UNICODE码】)
Unicode与UTF-8互转(C语言实现):http://blog.csdn.net/tge7618291/article/details/7599902 汉字 Unicode 编码范围:http: ...
- rabbitmq-direct(直接交换模式)
生产者和消费者,具有相同的交换机名称(Exchange).交换机类型和相同的密匙(routingKey),那么消费者即可成功获取到消息.(PS:相对比只要交换机名称即可接收到消息的广播模式(fanou ...
- Linux开机显示模式切换
修改vim /etc/inittab 默认为5-图形界面模式,改为3-多用户模式即可 # Default runlevel. The runlevels used are: # 0 - halt (D ...
- CocoaPods使用专题 by h.l
cocoaPods安装 CocoaPods安装和使用教程(code4app) cocoapods使用问题解决 cocoapods慢如何解决? CocoaPods停在Analyzing dependen ...
- 一个实用批处理指令制作过程分享:Perforce更新完后打开VisualStudio再编译
需求来源 笔者从事Unreal游戏客户端工作,使用VisualStudio开发,然后经常干一个事:就是使用Perforce(或svn)拉取最新代码,(一些时间后)拉取完之后然后打开 项目.sln,即V ...
- Vue3.X安装
1.查看node.js和npm版本 $ node -v //建议v10以上版本 $ npm -v 2.若已安装了2.x的旧版本,需要先卸载 npm uninstall vue-cli -g 3.安装淘 ...
- python多版本切换
环境:Macbook MacOS自带的python2.7,在命令行中输入python后会显示2.7版本 如何切换成新版本? 一.修改用户配置环境变量~/.bash_profile 确定新版本的安装位置 ...
- 总结下Mac环境下按照appium
第10天休息 先来总结下Mac环境下按照appium 一.相关网站 官网: http://appium.io/ 测试论坛 https://testerhome.com/wiki 二.环境准备 从官 ...
- Springboot+Websocket+JWT实现的即时通讯模块
场景 目前做了一个接口:邀请用户成为某课程的管理员,于是我感觉有能在用户被邀请之后能有个立马通知他本人的机(类似微博.朋友圈被点赞后就有立马能收到通知一样),于是就闲来没事搞了一套. 涉及技术栈 ...