Auto Validate 是一个 Flutter 包,通过可自定义的正则表达式简化输入验证。它使开发者能够以最少的代码高效验证电子邮件、电话号码和自定义模式等数据格式。该包可无缝集成到表单中,提供实时反馈并减少样板验证逻辑。专为跨平台使用设计,支持 Android、iOS、Web、macOS、Windows 和 Linux,使其成为在不同环境中实现一致验证的理想选择。
适合场景
表单输入验证
实时用户反馈
电子邮件和电话号码验证
自定义模式匹配
跨平台应用
减少验证样板代码
主要特点
可自定义的正则表达式模式
实时验证
跨平台支持
最小设置
与 TextFormField 的集成
灵活的错误处理
适合对象
开发表单的开发者
需要严格输入验证的应用程序
注重代码简洁性的团队
面向多个平台的项目
面向前端的 Flutter 应用程序
使用建议
需要理解正则表达式语法
可能需要为错误消息添加额外的样式
不适用于复杂业务逻辑验证
有限的内置验证器,超出正则表达式
取决于正确的正则表达式设计以确保准确性
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
Auto Validate
The Auto Validate Package is a unique and easy-to-use solution for automatic validation of various data types using regular expressions.
Importance
This package streamlines the validation process, allowing you to easily implement validation without needing to write the code yourself. By using this package, you can save valuable time and ensure that your input data meets the required criteria.
Usage
Here's a simple example of how to use the Auto Validate package:
String Validation Extension [New Feature]
This package provides an extension on String? that offers convenient methods for validating various input formats using the AutoValidate class. It allows for a more readable and fluent validation process in your Dart applications.
Features
Validate usernames, passwords, email addresses, phone numbers, credit card numbers, and more.
Check for valid formats like ISBN, MAC addresses, hexadecimal codes, and JSON Web Tokens (JWT).
Simplify validation checks by using fluent methods directly on String? instances.
Improve code readability and maintainability by using the extension methods for validation.
import'package:auto_validate/auto_validate.dart';
voidvalidation() {
var email = 'Dev.M.ElShenawy@Icloud.com';
var name = 'Mahmud El Shenawy';
var password = '@MahmoudElShenawy2021';
var phone = '+201098415860';
// You can validate the input using the AutoValidate classAutoValidate.email(email.toString())
? print('Email is Valid')
: print('Email is Invalid');
AutoValidate.userName(name.toString())
? print('User Name is Valid')
: print('User Name is Invalid');
AutoValidate.password(password.toString())
? print('Password is Valid')
: print('Password is Invalid');
AutoValidate.phone(phone.toString())
? print('Phone is Valid')
: print('Phone is Invalid');
// You can also use the extension methods to validate the input
email.isValidEmail
? print('Email is Valid')
: print('Email is Invalid');
name.isValidUsername
? print('User Name is Valid')
: print('User Name is Invalid');
password.isValidPassword
? print('Password is Valid')
: print('Password is Invalid');
phone.isValidPhone
? print('Phone is Valid')
: print('Phone is Invalid');
}