Codeigniter form validation. Alpha and spaces

前端 未结 6 630
逝去的感伤
逝去的感伤 2021-01-04 21:23

When using Codeigniter form validation, does alpha allow spaces? Ex. \"Bob Smith\"

6条回答
  •  执笔经年
    2021-01-04 21:54

    You can use

    $field = trim($_POST['field']);
    $_POST['field'] = str_replace(' ', '', $_POST['field']);
    

    and check it as alpha in the rule, then you can use $field after successful validation.

    $this->form_validation->set_rules('field', 'FIELD', 'alpha');
    

提交回复
热议问题