edtsz/f3-form-validator

基于CodeIgniter表单验证库的FatFreeFramework表单验证器

1.1.1 2017-02-17 21:59 UTC

This package is not auto-updated.

Last update: 2024-09-27 23:12:01 UTC


README

这是一个CodeIgniter (GitHub) 表单验证库,已移植到FatFreeFramework (GitHub)

入门指南

安装

将以下内容添加到您的composer.json文件中

{
    "require": {
        "edtsz/f3-form-validator": "1.0.0"
    }
}

然后,在项目目录中打开终端并运行:composer install

运行

$validator = new \Validator();
$validator->set_db( $f3->get('db.instance') ); // just if will use "is_unique"
$validator->set_rules(
	'username', 'Username',
	'required|min_length[5]|max_length[12]|is_unique[users.username]',
	array(
		'required'  => 'You have not provided %s.',
		'is_unique' => 'This %s already exists.'
	)
);
$validator->set_rules('password', 'Password',              'required');
$validator->set_rules('passconf', 'Password Confirmation', 'required|matches[password]');
$validator->set_rules('email',    'Email',                 'required|valid_email|is_unique[users.email]');

if ( $validator->run() === TRUE )
{
	// success
}
else
{
	print_r( $validator->error_array() );
}

有关如何使用的完整信息: CI 文档

可用的验证器|过滤器

CodeIgniter

  • required
  • regex_match
  • matches
  • differs
  • is_unique
  • min_length
  • max_length
  • exact_length
  • valid_url
  • valid_email
  • valid_emails
  • valid_ip
  • alpha
  • alpha_numeric
  • alpha_numeric_spaces
  • alpha_dash
  • numeric
  • integer
  • decimal
  • greater_than
  • greater_than_equal_to
  • less_than
  • less_than_equal_to
  • in_list
  • is_natural
  • is_natural_no_zero
  • valid_base64
  • prep_for_form
  • prep_url
  • strip_image_tags
  • encode_php_tags

GUMP

  • min_age
  • max_age
  • valid_name

自定义

  • is_file
  • file_min_size
  • file_max_size
  • file_types
  • valid_cpf
  • valid_date
  • valid_datetime
  • valid_time
  • convert_case
  • substr

CI 文档所述:“您还可以使用任何允许最多两个参数的本地PHP函数,其中至少需要一个参数(传递字段数据)。”

来源

待办事项

  • 改进文档
  • 示例
  • 测试