TODO vue的表单验证
访问量: 2229
参考: https://m.dotdev.co/form-validation-using-vue-js-2-35abd6b18c5d 和 https://github.com/logaretm/vee-validate
现在在用vue 2.0. 考察了几个插件,只有这个可以很好的支持。
安装:
修改 package.json, 添加这个 dependency:
"vee-validate": "^2.0.0-beta.25"
另一种 quick and dirty的方法:
if(this.phone == '' || !(/^\d+$/.test(this.phone))){ alert("请输入联系电话, 纯数字, 例如 13566668888 或者 01066668888 ") return } if(this.email == '') { alert("请输入电子邮箱") return } else if(! /\S+@\S+\.\S+/.test(this.email)){ alert("电子邮箱的格式应该形如 [email protected] ") return }