パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.0.0+1

regexed_validator

検証: 電話番号、名前、郵便番号、メールアドレス、URL、通貨、IP、日付、時刻、HTMLタグ、パスワード(強力)、中程度のパスワード、クレジットカード。Dart/Flutter開発者向け

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
47
いいね数
55
Pub ポイント
150

パッケージをインストール

flutter pub add regexed_validator

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

regexed_validator は、メールアドレス、電話番号、クレジットカード、パスワード、URL、IPアドレス、日付など一般的なデータタイプ向けに事前に構築された正規表現を提供することで、フォーム検証を簡素化するためのDart/Flutterパッケージです。開発者が信頼性があり再利用可能な検証ロジックを提供し、Android、iOS、Web、macOS、Windows、Linuxで正確な入力形式を保証します。このパッケージは強力なパスワードと中程度のパスワード強度チェック、HTMLタグ検証、通貨フォーマットに対応しており、堅牢なユーザーフォームの構築に最適です。明確な構文とpub.devを通じた簡単な統合により、開発者の生産性を向上させながらボイラープレートコードを削減します。

用途

  • フォーム入力検証
  • ユーザー登録フロー
  • セキュアなパスワードチェック
  • 住所および連絡先フォームの処理
  • モバイルおよびWebアプリケーションにおけるデータ整合性
  • APIリクエストペイロードの検証

主な機能

  • 12種類以上のデータ型用の事前定義された正規表現パターン
  • パスワード強度の検証(強/中)
  • クロスプラットフォーム互換性
  • Flutter フォームとの簡単な統合
  • 国際的なフォーマットのサポート
  • 軽量で依存関係なし

適している対象

  • Flutter開発者がフォームを構築しています
  • 厳密な入力検証を必要とするアプリ
  • 再利用可能な検証ロジックを求める開発者
  • 複数のプラットフォームをターゲットにするプロジェクト
  • コードの一貫性を重視するチーム
  • 迅速なフォーム開発が必要なスタートアップ

注意事項

  • エラーメッセージの手動処理が必要です
  • 複雑な検証ルールに対するカスタマイズの制限
  • 組み込みのローカライゼーションサポートなし
  • 外部の正規表現パターンに依存しています
  • 非常に動的な検証シナリオには適していません
  • 高度なフォーム管理には追加パッケージが必要になる場合があります

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Validating:

  • phone
  • name
  • postalCode
  • email
  • url
  • currency
  • ip
  • date
  • time
  • htmlTags
  • password (strong)
  • password (medium)
  • creditCard

For Dart/Flutter developers. Regexed Validator at pub.dartlang.org

Usage

Usage is pretty simple just pass a phone, date, email... to its validation method, see the example below

import 'package:regexed_validator/regexed_validator.dart';

main() {
  print( validator.email('example@example.co.uk') ); // true

  print(validator.url('http://www.nowhere.com?product=28&color=blue')); // true

  print(validator.currency('£498.10')); // true

  print(validator.ip('67.52.159.38')); // true

  print(validator.time('14:34 GMT -5')); // true

  print( validator.htmlTags('<strong>Bold</strong>\n'
          '<em>Emphazied</em>\n'
          '<b>Bold</b>\n'
          '<i>Italics</i>\n'
          '<span id="foo" class="bar">Some text</span>\n'
          '<hr />')
  ); // true
}

With Flutter TextField, TextFormField and Form(s)

There is nothing specific to this package when working with Forms and TextFields, see the example below

TextFormField(
    // The validator receives the text that the user has entered, and use regexed_validator to check if it is a valid string.
    validator: (value) {
      if (!validator.email(value)) {
        return 'Please enter a valid email';
      }
      return null;
    },
  ),

Here is a complete example, with a Form and an email field:

import 'package:flutter/material.dart';
import 'package:regexed_validator/regexed_validator.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    const appTitle = 'Form Validation Demo';

    return MaterialApp(
      title: appTitle,
      home: Scaffold(
        appBar: AppBar(
          title: const Text(appTitle),
        ),
        body: const MyCustomForm(),
      ),
    );
  }
}

// Create a Form widget.
class MyCustomForm extends StatefulWidget {
  const MyCustomForm({Key? key}) : super(key: key);

  @override
  MyCustomFormState createState() {
    return MyCustomFormState();
  }
}

// Create a corresponding State class.
// This class holds data related to the form.
class MyCustomFormState extends State<MyCustomForm> {
  // Create a global key that uniquely identifies the Form widget
  // and allows validation of the form.
  //
  // Note: This is a GlobalKey<FormState>,
  // not a GlobalKey<MyCustomFormState>.
  final _formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    // Build a Form widget using the _formKey created above.
    return Form(
      key: _formKey,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          TextFormField(
            // The validator receives the text that the user has entered, and use regexed_validator to check if it is a valid string.
            validator: (value) {
              if (value == null || !validator.email(value)) {
                return 'Please enter a valid email';
              }
              return null;
            },
          ),
          Padding(
            padding: const EdgeInsets.symmetric(vertical: 16.0),
            child: ElevatedButton(
              onPressed: () {
                // Validate returns true if the form is valid, or false otherwise.
                if (_formKey.currentState!.validate()) {
                  // If the form is valid, display a snackbar. In the real world,
                  // you'd often call a server or save the information in a database.
                  ScaffoldMessenger.of(context).showSnackBar(
                    const SnackBar(content: Text('Processing Data')),
                  );
                }
              },
              child: const Text('Submit'),
            ),
          ),
        ],
      ),
    );
  }
}

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト