Skip to content

Commit c83ca8f

Browse files
committed
正規表現の修正
1 parent 2b4315e commit c83ca8f

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/components/InputField.vue

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
v-model="value"
55
:color="textFieldColor"
66
:type="show ? 'text' : 'password'"
7+
:hint="hint"
78
:label="label"
89
background-color="white"
910
class="elevation-0"
@@ -27,6 +28,7 @@
2728
v-model="value"
2829
:color="textFieldColor"
2930
type="text"
31+
:hint="hint"
3032
:label="label"
3133
background-color="white"
3234
class="elevation-0"
@@ -43,6 +45,7 @@
4345
v-model="value"
4446
:color="textFieldColor"
4547
type="text"
48+
:hint="hint"
4649
:label="label"
4750
background-color="white"
4851
class="elevation-0"
@@ -59,6 +62,7 @@
5962
v-model="value"
6063
:color="textFieldColor"
6164
type="text"
65+
:hint="hint"
6266
:label="label"
6367
background-color="white"
6468
class="elevation-0"
@@ -115,11 +119,16 @@ export default Vue.extend({
115119
},
116120
computed: {
117121
prependIconColor(): string {
122+
const classIdPattern = /^[あ-ん]{6}$/
118123
if (this.type === 'classId') {
119-
if (!this.value || this.value.length !== 6) return '#C01B61'
124+
if (!this.value || !classIdPattern.test(this.value)) return '#C01B61'
120125
}
121126
if (this.type === 'email') {
122-
if (!this.value || !this.value.match(/.+@.+\..+/)) return '#C01B61'
127+
if (
128+
!this.value ||
129+
!this.value.match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/)
130+
)
131+
return '#C01B61'
123132
}
124133
if (this.require) {
125134
if (!this.value) return '#C01B61'
@@ -130,23 +139,33 @@ export default Vue.extend({
130139
return '#BDBDBD'
131140
},
132141
textFieldColor(): string {
142+
const classIdPattern = /^[あ-ん]{6}$/
133143
if (this.type === 'classId') {
134-
if (!this.value || this.value.length !== 6) return '#C01B61'
144+
if (!this.value || !classIdPattern.test(this.value)) return '#C01B61'
135145
}
136146
if (this.type === 'email') {
137-
if (!this.value || !this.value.match(/.+@.+\..+/)) return '#C01B61'
147+
if (
148+
!this.value ||
149+
!this.value.match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/)
150+
)
151+
return '#C01B61'
138152
}
139153
if (this.require) {
140154
if (!this.value) return '#C01B61'
141155
}
142156
return '#0071C2'
143157
},
144158
prependIcon(): string {
159+
const classIdPattern = /^[あ-ん]{6}$/
145160
if (this.type === 'classId') {
146-
if (!this.value || this.value.length !== 6) return 'mdi-alert-circle'
161+
if (!this.value || !classIdPattern.test(this.value))
162+
return 'mdi-alert-circle'
147163
}
148164
if (this.type === 'email') {
149-
if (!this.value || !this.value.match(/.+@.+\..+/))
165+
if (
166+
!this.value ||
167+
!this.value.match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/)
168+
)
150169
return 'mdi-alert-circle'
151170
}
152171
if (this.require) {

0 commit comments

Comments
 (0)