<!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-表单验证的更多相关文章

  1. vue表单验证--veevalidate使用教程

    vue表单验证----vee-validate使用教程 官网:https://baianat.github.io/vee-validate/ 一.安装 npm install vee-validate ...

  2. 写一个简单易用可扩展vue表单验证插件(vue-validate-easy)

    写一个vue表单验证插件(vue-validate-easy) 需求 目标:简单易用可扩展 如何简单 开发者要做的 写了一个表单,指定一个name,指定其验证规则. 调用提交表单方法,可以获取验证成功 ...

  3. vue 表单验证实例

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

  4. vue表单验证:vee-validate中文提示

    官方文档:https://baianat.github.io/vee-validate/guide/ vee-validate可用于vue项目中进行表单验证,使用方法在官方API上都可以查到: 使用过 ...

  5. Vue表单验证插件的制作过程

    一.表单验证模块的构成 任何表单验证模块都是由 配置――校验――报错――取值 这几部分构成的. 配置: 配置规则 和配置报错,以及优先级 校验: 有在 change 事件校验, 在点击提交按钮的时候校 ...

  6. Vue 表单验证插件

    verify github:https://github.com/liuyinglong/verifynpm:https://www.npmjs.com/package/vue-verify-plug ...

  7. vue 表单验证省市县三联动

    <el-col :span="24"> <el-form-item label="所在地区" prop="region" ...

  8. vue表单验证不通过,依然能执行点击事件里面的代码?

    遇到的问题:表单提交的时候,写了rules,明明验证不通过依然执行了点击事件里面的代码. 这个验证有什么用? 后来 我看elementUI组件才发现,我漏写了几行代码. methods里面这样写 完美 ...

  9. 一个不错的vue表单验证插件

    github文档 用着不错,官方的文档例子很简单 <body> <div id="app"> <validator name="valida ...

  10. vue 表单 验证 async-validator

    1.使用插件async-validator async-validator 地址:https://github.com/yiminghe/async-validator 2.示例(vue+elemen ...

随机推荐

  1. mysql获取表中的字段名

    转载请注明来源:https://www.cnblogs.com/hookjc/ SELECT COLUMN_NAME FROM 'information_schema'.'COLUMNS' where ...

  2. 广播接收者案例_ip拨号器

    (1)定义一个类继承BroadCastReceiver public class OutGoingCallReceiver extends BroadcastReceiver { //当接收到外拨电话 ...

  3. scons: 使用 SCons 轻松建造程序

    转载请注明来源:https://www.cnblogs.com/hookjc/ 在软件项目开发过程中,make 工具通常被用来建造程序.make 工具通过一个被称为 Makefile 的配置文件可以自 ...

  4. drop、delete和truncate三者的区别

    相同点:1.truncate和不带where子句的delete.以及drop都会删除表内的数据.2.drop.truncate都是DDL语句(数据定义语言),执行后会自动提交.不同点:1. trunc ...

  5. System 系统类

    import java.util.Arrays; import java.util.Properties; /* System 系统类 主要用于获取系统的属性数据. System类常用的方法: arr ...

  6. jqGrid 修改单元格值或者替换图片及其他

     var rowIds = jQuery("#list1").jqGrid('getDataIDs');                for (var k = 0; k < ...

  7. 反射(reflection),通过反射创建对象

    简单尝试: import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public cl ...

  8. pycharm工具使用

    转自: https://blog.csdn.net/u014044812/article/details/78727496   因公司的需求,需要做一个爬取最近上映的电影.列车号.航班号.机场.车站等 ...

  9. 【JOISC 2020 补题记录】

    目录 Day 1 Building 4 Hamburg Steak Sweeping Day 2 Chameleon's Love Making Friends on Joitter is Fun R ...

  10. Solution -「UOJ #450」复读机

    \(\mathcal{Description}\)   Link.   求从 \(m\) 种颜色,每种颜色无限多的小球里选 \(n\) 个构成排列,使得每种颜色出现次数为 \(d\) 的倍数的排列方案 ...