質問編集履歴
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -55,3 +55,67 @@
|
|
55
55
|
})();
|
56
56
|
|
57
57
|
```
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
**現状の打開策**
|
62
|
+
|
63
|
+
下記のように``addEventListener``を二つ作る事でやりたいことを実現はできます。
|
64
|
+
|
65
|
+
しかし、処理内容がほぼ一緒なのでなんとかして1つにまとめる方法について知りたいです。
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
```js
|
70
|
+
|
71
|
+
(function () {
|
72
|
+
|
73
|
+
'use strict';
|
74
|
+
|
75
|
+
var text = document.getElementById("mail");
|
76
|
+
|
77
|
+
var other = document.getElementById("label");
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
inputText.addEventListener('keyup', function() {
|
82
|
+
|
83
|
+
var s = text.value;
|
84
|
+
|
85
|
+
var check = !!s.match(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)*$/);
|
86
|
+
|
87
|
+
if(!!s && check){
|
88
|
+
|
89
|
+
other.textContent = "Good";
|
90
|
+
|
91
|
+
}else{
|
92
|
+
|
93
|
+
other.textContent = "Bad";
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
}, false);
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
inputText.addEventListener('paste', function() {
|
102
|
+
|
103
|
+
var s = text.value;
|
104
|
+
|
105
|
+
var check = !!s.match(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)*$/);
|
106
|
+
|
107
|
+
if(!!s && check){
|
108
|
+
|
109
|
+
other.textContent = "Good";
|
110
|
+
|
111
|
+
}else{
|
112
|
+
|
113
|
+
other.textContent = "Bad";
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
}, false);
|
118
|
+
|
119
|
+
})();
|
120
|
+
|
121
|
+
```
|