回答編集履歴

1

filter

2019/03/12 09:17

投稿

yambejp
yambejp

スコア114769

test CHANGED
@@ -11,3 +11,59 @@
11
11
  if(!preg_match('/^[a-z][a-z0-9_]{5,19}$/i', $pw)){
12
12
 
13
13
  ```
14
+
15
+
16
+
17
+ # filter処理
18
+
19
+
20
+
21
+ ```PHP
22
+
23
+ <?php
24
+
25
+ $message = NULL;
26
+
27
+ $mail = filter_input(INPUT_POST,'mail',FILTER_VALIDATE_REGEXP,["options"=>["regexp"=>"/^(([a-z\d])+([\w.-])*@([\w-])+([\w.-]+)+|)$/i"]]);
28
+
29
+ $pw = filter_input(INPUT_POST,'pw',FILTER_VALIDATE_REGEXP,["options"=>["regexp"=>"/^([a-z]\w{5,19}|)$/i"]]);
30
+
31
+
32
+
33
+ if(!is_null($mail)){
34
+
35
+ $message = '登録完了';
36
+
37
+ if($pw==="") $message = 'パスワードを入力してください';
38
+
39
+ if($pw===false) $message = 'パスワードは6文字以上20文字以内で入力してください';
40
+
41
+ if($mail==="") $message = 'メールアドレスを入力してください';
42
+
43
+ if($mail===false) $message = 'メールアドレスの形式が正しくありません';
44
+
45
+ }
46
+
47
+
48
+
49
+ var_dump([$mail,$pw,$message]);
50
+
51
+ ?>
52
+
53
+ <form method="post">
54
+
55
+ <p><label for="mail">メールアドレス<br/>
56
+
57
+ <input type="text" name="mail" id="mail"></label></p>
58
+
59
+ <p><label for="pw">パスワード<br/>
60
+
61
+ <input type="password" name="pw" id="pw"></label></p>
62
+
63
+ <p><input type="submit" name="登録"></p>
64
+
65
+ </form>
66
+
67
+
68
+
69
+ ```