標籤:ida 內容 span mit 不能 blog cte ring 表單
1. 驗證文字框是否有內容且不可為空
<?php
if (! (filter_has_var(INPUT_POST, ‘flavor‘) && (strlen(filter_input(INPUT_POST, ‘flavor‘)) > 0))) { print ‘You must enter your favorite ice cream flavor.‘;}
2. 驗證字串個數
<?phpif (! (filter_has_var(INPUT_POST, ‘color‘) && (strlen(filter_input(INPUT_POST, ‘color‘, FILTER_SANITIZE_STRING)) <= 5))) { print ‘Color must be more than 5 characters.‘;}
3. 驗證是否是數組
<?phpif (! (filter_has_var(INPUT_POST, ‘choices‘) && filter_input(INPUT_POST, ‘choices‘, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY))) { print ‘You must select some choices.‘;}
4. 驗證是否是整數
<?phpif (! (filter_has_var(INPUT_POST, ‘age‘) && filter_input(INPUT_POST, ‘age‘, FILTER_VALIDATE_INT))) { print "Submitted age is invalid.";}
5. 驗證是否是浮點數
<?phpif (! (filter_has_var(INPUT_POST, ‘price‘) && filter_input(INPUT_POST, ‘price‘, FILTER_VALIDATE_FLOAT))) { print "Submitted age is invalid.";}
PHP 表單驗證