패키지, 저장소 및 앱 카테고리 검색

패키지 상세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 패키지입니다. 개발자에게 신뢰할 수 있고 재사용 가능한 검증 로직을 제공하여 안드로이드, iOS, 웹, macOS, Windows, 리눅스에서 입력 형식의 정확성을 보장합니다. 강력한 및 중간 수준의 비밀번호 강도 검사, HTML 태그 검증, 통화 형식 지정을 지원하여 견고한 사용자 폼을 구축하는 데 이상적입니다. 명확한 문법과 pub.dev를 통한 간편한 통합으로 개발 생산성을 향상시키며 봐야 할 코드를 줄입니다.

사용 사례

  • 폼 입력 검증
  • 사용자 등록 흐름
  • 보안 비밀번호 확인
  • 주소 및 연락처 폼 처리
  • 모바일 및 웹 앱에서의 데이터 무결성
  • API 요청 본문 검증

주요 기능

  • 12개 이상의 데이터 유형용 사전 정의된 정규 표현식 패턴
  • 비밀번호 강도 검증(강/중)
  • 크로스 플랫폼 호환성
  • 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'),
            ),
          ),
        ],
      ),
    );
  }
}

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트