Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/scniro/scniro-validator


https://github.com/scniro/scniro-validator

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

> a small, dependency-free email validator with configurable rules and suggested corrections

### Install

```
npm install scniro-validator --save
```

### Sample usage

```javascript
var v = require('scniro-validator');

var result = v.validate('[email protected]');
// {valid: true}
```

### Configuration

validation may be influenced by calling optional `.init` with a configuration object

```javascript
var rules = {
tld: {
allowed: ['com']
sdl: {
allowed: ['bar']
}
}

var result = v.validate('[email protected]');
// {valid: false}
```

### Corrections

validation will include a suggested correction base on `corrections` defined via `tld` and `sld` supplied `match` objects ([top-level domain](https://en.wikipedia.org/wiki/Top-level_domain) and [second-level domain](https://en.wikipedia.org/wiki/Second-level_domain), respectively). Specify this via `tryCorrect`.

```javascript
var rules = {
tld: {
allowed: ['com'],
corrections: [
{match: 'con.au', correct: 'com'}
]
}
}

var result = v.validate('[email protected]', {tryCorrect: true});
// {valid: false, correction: '[email protected]'}
```

or a _really_ barged example

```javascript
var rules = {
tld: {
allowed: ['com'],
corrections: [
{match: 'con.au', correct: 'com'}
]
},
sdl: {
allowed: ['bar']
}
}

var result = v.validate('foo.bar.con.au', {tryCorrect: true});
// {valid: false, correction: '[email protected]'}
```

### Note

e-mail validation is a [rabbit hole]( http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx/), and this tool does not aim to be a silver bullet. The capability of this tool is influenced from the [w3c `type="email"`](https://www.w3.org/TR/html-markup/input.email.html#input.email.attrs.value.multiple) validation, ships with some extensibility specific to a business defined problem, and is pessimistic in nature. For a less problem-specific validation tool, check out the awesome [mailcheck.js](https://github.com/mailcheck/mailcheck)