• Stars
    star
    64
  • Rank 463,099 (Top 10 %)
  • Language
    Dart
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🐢 String validation and sanitization for Dart.

validator.dart

Build Status

String validation and sanitization for Dart.

Port of chriso's library.

Usage

Documentation

Complete documentation of the package is available at http://www.dartdocs.org/documentation/validator/0.0.7/index.html#validator/validator

For a list of methods, refer to the sections below.

1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  validator: ">=0.0.4 <0.1.0"

2. Install it

You can install packages from the command line:

$ pub get

Alternatively, your editor might support pub. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:validator/validator.dart';

Validators

  • equals(String str, comparison) - check if the string matches the comparison.
  • contains(String str, seed) - check if the string contains the seed.
  • matches(String str, pattern) - check if string matches the pattern. matches('foobar', 'foo').
  • isEmail(String str) - check if the string is an email.
  • isURL(String str [, options]) - check if the string is an URL. options is an object which defaults to { protocols: ['http','https','ftp'], require_tld: true, require_protocol: false, allow_underscores: false, host_whitelist: false, host_blacklist: false }.
  • isFQDN(String str [, options]) - check if the string is a fully qualified domain name (e.g. domain.com). options is an object which defaults to { require_tld: true, allow_underscores: false }.
  • isIP(String str [, version]) - check if the string is an IP (version 4 or 6).
  • isAlpha(String str) - check if the string contains only letters (a-zA-Z).
  • isNumeric(String str) - check if the string contains only numbers.
  • isAlphanumeric(String str) - check if the string contains only letters and numbers.
  • isBase64(String str) - check if a string is base64 encoded.
  • isHexadecimal(String str) - check if the string is a hexadecimal number.
  • isHexColor(String str) - check if the string is a hexadecimal color.
  • isLowercase(String str) - check if the string is lowercase.
  • isUppercase(String str) - check if the string is uppercase.
  • isInt(String str) - check if the string is an integer.
  • isFloat(String str) - check if the string is a float.
  • isDivisibleBy(String str, number) - check if the string is a number that's divisible by another.
  • isNull(String str) - check if the string is null.
  • isLength(String str, min [, max]) - check if the string's length falls in a range. Note: this function takes into account surrogate pairs.
  • isByteLength(String str, min [, max]) - check if the string's length (in bytes) falls in a range.
  • isUUID(String str [, version]) - check if the string is a UUID (version 3, 4 or 5).
  • isDate(String str) - check if the string is a date.
  • isAfter(String str [, date]) - check if the string is a date that's after the specified date (defaults to now).
  • isBefore(String str [, date]) - check if the string is a date that's before the specified date.
  • isIn(String str, values) - check if the string is in a array of allowed values.
  • isCreditCard(String str) - check if the string is a credit card.
  • isISBN(String str [, version]) - check if the string is an ISBN (version 10 or 13).
  • isJSON(String str) - check if the string is valid JSON (note: uses JSON.parse).
  • isMultibyte(String str) - check if the string contains one or more multibyte chars.
  • isAscii(String str) - check if the string contains ASCII chars only.
  • isFullWidth(String str) - check if the string contains any full-width chars.
  • isHalfWidth(String str) - check if the string contains any half-width chars.
  • isVariableWidth(String str) - check if the string contains a mixture of full and half-width chars.
  • isSurrogatePair(String str) - check if the string contains any surrogate pairs chars.
  • isMongoId(String str) - check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid].

Sanitizers

  • toString(String input) - convert the input to a string.
  • toDate(String input) - convert the input to a date, or null if the input is not a date.
  • toFloat(String input) - convert the input to a float, or NaN if the input is not a float.
  • toInt(String input [, radix]) - convert the input to an integer, or NaN if the input is not an integer.
  • toBoolean(String input [, strict]) - convert the input to a boolean. Everything except for '0', 'false' and '' returns true. In strict mode only '1' and 'true' return true.
  • trim(String input [, chars]) - trim characters (whitespace by default) from both sides of the input.
  • ltrim(String input [, chars]) - trim characters from the left-side of the input.
  • rtrim(String input [, chars]) - trim characters from the right-side of the input.
  • escape(String input) - replace <, >, &, ' and " with HTML entities.
  • stripLow(String input [, keep_new_lines]) - remove characters with a numerical value < 32 and 127, mostly control characters. If keep_new_lines is true, newline characters are preserved (\n and \r, hex 0xA and 0xD). Unicode-safe in JavaScript.
  • whitelist(String input, chars) - remove characters that do not appear in the whitelist. The characters are used in a RegExp and so you will need to escape some chars, e.g. whitelist(String input, '\[\]').
  • blacklist(String input, chars) - remove characters that appear in the blacklist. The characters are used in a RegExp and so you will need to escape some chars, e.g. blacklist(String input, '\[\]').
  • normalizeEmail(String email [, options]) - canonicalize an email address. options is an object which defaults to { lowercase: true }. With lowercase set to true, the local part of the email address is lowercased for all domains; the hostname is always lowercased and the local part of the email address is always lowercased for hosts that are known to be case-insensitive (currently only GMail). Normalization follows special rules for known providers: currently, GMail addresses have dots removed in the local part and are stripped of tags (e.g. [email protected] becomes [email protected]) and all @googlemail.com addresses are normalized to @gmail.com.

Tests

To test the package, run:

$ ./tool/run_tests.sh

More Repositories

1

Projects

📃 A list of practical projects that anyone can solve in any programming language.
43,908
star
2

Projects-Solutions

📟 Links to others' solutions to Projects (https://github.com/karan/Projects/)
3,995
star
3

joe

🏃 A .gitignore magician in your command line
Go
2,860
star
4

slack-overflow

A programmer's best friend, now in Slack.
Python
815
star
5

HackerNewsAPI

📰 Unofficial Python API for Hacker News. RESTful API at https://github.com/karan/HNify
Python
389
star
6

TPB

☁️ Python API for ThePirateBay.
HTML
330
star
7

slack-news

Read news from multiple sources within Slack by just typing /news.
JavaScript
123
star
8

Swift-Algorithms

Implementation of various algorithms and data structures in Swift.
Swift
110
star
9

chrome-url-alias

Chrome extension to set URL aliases ("m/" goes to "mail.google.com" etc)
JavaScript
109
star
10

HNify

Hacker News REST API using Flask on Heroku using memcached.
Python
91
star
11

Hook

ProductHunt REST API (Unofficial) - DISCONTINUED
JavaScript
89
star
12

fleets

Automatically delete tweets, retweets, and favorites.
Go
88
star
13

SoundWall

A faster, more pleasant way to discover new music.
JavaScript
77
star
14

atom-terminal

Atom package to open terminal on current file's directory with "ctrl-shift-t"
CoffeeScript
70
star
15

vocabulary

Golang package to get meanings, synonyms, antonyms and more for a word
Go
59
star
16

slashgif

Post GIFs to Twitter by doing "@slashgif coffee break"
Python
55
star
17

Spear

Product Hunt for Hackers - a CLI to Product Hunt.
Python
52
star
18

scInstant

SoundCloud Instant Search
JavaScript
51
star
19

x-meme

The meme element for modern web
48
star
20

RedditAgain

Migrate an old Reddit account to a new one.
Python
44
star
21

slackzon

Simple Amazon Product Search in Slack
Python
39
star
22

Qnowledge

Knowledge API for Quora. (Code removed)
Python
39
star
23

dotfiles

~/* - all my dotfiles with bootstrapping script. 10X productivity gains. ❤️
Shell
39
star
24

slack-hn

SEE https://github.com/karan/slack-news INSTEAD
JavaScript
36
star
25

nojs.club

You don't need Javascript to make a beautiful, usable web. How it works: https://goel.io/nojs-club
SCSS
34
star
26

libfib

An experiment to run Go code directly from Python.
Python
29
star
27

brain2music

🎵 EEG brainwave data to music (more like noise) in realtime.
JavaScript
28
star
28

todo-swift

Very simple iOS todo list app built with Swift
Swift
26
star
29

NobodyDoesThis

Reddit bot that scans 3 day-old /r/DoesAnybodyElse posts with 0 score and then comments "Nope, it's just you."
Python
22
star
30

s

🌵 A high-performance, anonymous URL shortener built using Redis + Node.js with a API-backed design.
JavaScript
22
star
31

PebBus

⏰ Pebble app for OneBusAway.
JavaScript
21
star
32

language.dart

🌺 Natural language processing utilities for Dart
Dart
20
star
33

Storming

☔ Hacking The Tweetstorm... With Pictures of Text
CSS
16
star
34

What-Would-I-Tweet

Automatically generates tweets for you! It trains a Markov bot based on bigram probabilities derived from your tweet history.
CSS
14
star
35

slashRemindMe

A Twitter bot to remember things or threads. [INACTIVE]
Python
14
star
36

Projects-my

My solutions to Projects
Python
11
star
37

grpc-practical-tutorial

A practical gRPC tutorial
Ruby
10
star
38

Data-Structures-and-Algorithms

Data Structures and Algorithms with Object-Oriented Design Patterns in Python
Python
10
star
39

griddit

orgasmic reddit interface for image-based subreddits
JavaScript
10
star
40

x-math

Polymer element to embed beautiful math using just HTML.
JavaScript
10
star
41

gphotos-takeout

[WIP] Parse Google Takeout archive for Google Photos
Go
9
star
42

Speekr

Simple app to help learn spoken languages using experimental Chrome APIs
JavaScript
8
star
43

ZipUp

Helping your business go down.. (24-hour hackathon project. Do not try to make sense of code.)
JavaScript
8
star
44

slashStock

Get stock quotes in Twitter. (@slashStock GOOG)
Python
8
star
45

Singular

Mapping the world’s sounds.
JavaScript
8
star
46

statistics.dart

🐎 Functions for calculating mathematical statistics of numeric data.
Dart
7
star
47

Pillar

Suicide prevention app built at a hackathon. See pillar.pdf for pitch slides.
Java
6
star
48

PHDroid

Product Hunt Android App
Java
6
star
49

navi

Learn to code together. AngelHack Silicon Valley 2014 Hack.
JavaScript
6
star
50

sopins

Social badges on the fly. (Twitter, Facebook / png, svg)
Python
5
star
51

PlaySink

A new way to discover music you like.. (One of those things that never really happened)
JavaScript
5
star
52

UW-OpenData

An unofficial data API for UW course catalog.
Python
5
star
53

Flask-Tutorial

Following "The Flask Mega-Tutorial"
Python
5
star
54

AfterLands

Crowdsourced hyperlocal music playlists, Outside Hacks 2014 Project.
JavaScript
4
star
55

blog-dart

A blog written in Dart
Dart
4
star
56

unit

A highly modular, fast API framework in Golang, perfectly fitted for Docker
Go
4
star
57

oss.wtf

Get free subdomains for your OSS projects.
HCL
4
star
58

Gmail-Subject-Lines

Grab subject lines of gmail emails
Python
4
star
59

Zillow

Coding questions for internship @ Zillow
Java
4
star
60

Pixels

Know the pixels you see. A lazy Sunday afternoon hack.
Python
4
star
61

learneveryword

Learn every word in the English language. Task will complete in 2022.
Python
4
star
62

DataStructures

Data structures and algorithms in Java
Java
4
star
63

TakeoverBot

Twitter bot to monitor and respond to tweets promoting state-backed information operations
Go
4
star
64

generator-customelement

A Yeoman generator for scaffolding a Polymer custom element the right way
JavaScript
4
star
65

sc-embed

Web component wrapper for embedding SoundCloud tracks
4
star
66

entroPHy

Product Hunt roulette
CSS
4
star
67

SpamHarvestUW

All my code for analysis done in Spam Harvesting study: https://www.microryza.com/projects/how-do-spammers-harvest-your-e-mail-address
Python
4
star
68

dockerfiles

These are dockerfiles for images I use.
Dockerfile
3
star
69

Python-vs-Java-forks

Visualising usage of Python and Java throughout the world using WebGL Globe
JavaScript
3
star
70

dart-hn

A very basic HN client in Dart.
Dart
3
star
71

summarize

A very basic script to summarize any piece of content (text). Still in progress.
Python
3
star
72

Pillar-API

API for backend of Suicide Prevention App
JavaScript
3
star
73

MoodicPlayer

Build your last.fm playlist based on your mood.
Java
3
star
74

Tech_Poster

A script that posts tech news to /r/technology
Python
2
star
75

oldblog

My old blog
CSS
2
star
76

TOPS-GiveCamp

Email marketing system made for Timebanks at GiveCamp Seattle 2013.
JavaScript
2
star
77

Euler

My solutions to Project Euler using Python
Python
2
star
78

typeof.dart

typeOf in Dart.
Dart
2
star
79

LastFMSessionKeyFinder

Easily generate Last.FM session key for your developments
Java
2
star
80

ms.dart

Tiny milisecond conversion utility for Dart.
Dart
2
star
81

PyFibonacci

Simple python script that prints fibonacci series
Python
2
star
82

kubernetes

Production-Grade Container Scheduling and Management
Go
2
star
83

baby-tracker-api

Backend to get Jawbone UP data, crunch it and send to the client. PennApps Fall 2014.
JavaScript
2
star
84

Awear

Context aware wearables
JavaScript
2
star
85

Interviews

interview problems and solutions
Python
2
star
86

ThisForThat

A pure Python implementation of itsthisforthat.com
Python
2
star
87

SmartCradle

Saving infant lives by alarming when they sleep with chest down. PennApps Fall 2014.
Arduino
2
star
88

inside-api

😆 See last commit in this repo.
JavaScript
1
star
89

SWSEAedu

All my stuff for Startup Weekend SEA Edu
Python
1
star
90

x-sarcasm

<sarcasm></sarcasm>
HTML
1
star
91

YALT

Yet Another Learning Tool (YALT) is a lightweight and minimal utility to make it easier for you to remember things.
Java
1
star
92

node-slides

JavaScript
1
star
93

slashZoomEnhance

Zoom, Enhance... on Twitter [doesn't work quite well]
Python
1
star
94

Valyoo

Dumping all my code files for Valyoo Technologies. They will not make any practical sense without the data.
Python
1
star
95

read-wsj

We Know You're Just Going To Google This Headline Anyway, So Here Is A Link To The Free Article, You Cheap Bastard
JavaScript
1
star
96

ARCH-251

My lecture notes for ARCH 251 at UW
1
star
97

have.tips

have.tips homepage
CSS
1
star
98

weebly

A mini-weebly.
JavaScript
1
star
99

ZipUp-private

A public fork of ZipUp that *was* being deployed and actively developed.
Java
1
star
100

pyFizzBuzz

FizzBuzz in Python
Python
1
star