質問編集履歴
1
正規表現追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
半角【英小文字、英大文字、数字、記号】4種類より2種類以上を使用した正規表現となっています
|
2
2
|
|
3
3
|
さらに、同じ文字列を3文字連続を禁止にしたい場合はどのように書けば良いでしょうか。
|
4
4
|
|
@@ -20,6 +20,34 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
``
|
23
|
+
```
|
24
24
|
|
25
|
+
class PasswordValidator < ActiveModel::EachValidator
|
26
|
+
|
27
|
+
def validate_each(record, attribute, value)
|
28
|
+
|
29
|
+
a = /\A(?=.*?[a-z])(?=.*?\d)[a-z\d]|(?=.*?[A-Z])(?=.*?\d)[A-Z\d]|(?=.*[!@;:])(?=.*?\d)[!@;:\d]+\z/
|
30
|
+
|
31
|
+
b = /\A(?=.*?[a-z])(?=.*?[A-Z])[a-zA-Z]|(?=.*?[a-z])(?=.*[!@;:])[a-z!@;:]+\z/
|
32
|
+
|
33
|
+
c = /\A(?=.*?[A-Z])(?=.*[!@;:])[A-Z!@;:]+\z/i
|
34
|
+
|
35
|
+
password = /
|
36
|
+
|
37
|
+
#{a}|
|
38
|
+
|
39
|
+
#{b}|
|
40
|
+
|
41
|
+
#{c}
|
42
|
+
|
43
|
+
/x
|
44
|
+
|
45
|
+
format = password
|
46
|
+
|
47
|
+
record.errors.add(attribute, :invalid) unless format =~ value
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
25
|
-
``
|
53
|
+
```
|