-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue-validator-example.js
50 lines (47 loc) · 1.35 KB
/
vue-validator-example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Vue.config.devtools = true;
Vue.config.debug = true;
Vue.validator('email', function (val) {
return /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(val);
});
new Vue({
el: '#validatorContainer',
validators: {
passwordValidator: function (val, target) {
return val === target;
}
},
data: {
confirmPassword: "", // this only is here to clean when a user is saved
user: {
firstName: "",
lastName: "",
country: "",
email: "",
password: "",
},
userList: [],
showValidatorJson: false
},
ready: function () {
},
methods: {
saveUser: function () {
this.$validate(true);
if (this.$sampleValidator.valid) {
this.userList.push(this.user);
/*this.user = {
firstName: "",
lastName: "",
country: "",
email: "",
password: "",
};
this.confirmPassword = "";*/
this.$resetValidation();
}
},
removeUser: function(user) {
this.userList.$remove(user);
}
},
});