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');
}