我想在codeigniter中的文本框表单验证中只接受英文字符。 是否有任何内置的表单验证方法,或者我应该使用自己的验证函数来实现它?
答案 0 :(得分:3)
您需要的规则是alpha。你可以这样做:
$this->form_validation->set_rules('text', 'Text','required|alpha');
确保输入的内容仅包含字母值。
请参阅codeigniter文档中的rule reference。
答案 1 :(得分:0)
试图找到解决方案3天....上面一个不能通过空间,下划线,连字符等等....
所以我做了什么来过滤和传递英文字符: (对我很好....也许很愚蠢,但我尝试了很多选项!没有工作但只有这一个)
$this->load->helper('text');
$yourText = ascii_to_entities($yourText,true);
if (strpos($yourText,'&#') !== false) {
echo 'use English only';
}else {
echo 'all good';
}