email-syntax
v2.0.2
Published
Email addresses syntax validations library
Downloads
96
Maintainers
Readme
email-syntax
Email addresses syntax validations library
Syntax email addresses verification based on RFC5321 and RFC5322. Version 2 is full remake of original one using TypeScript. Now it's a class with one static method "validate". Library can be used in Node.js back-end and in Angular 4 front-end projects.
Installation
Install Email Syntax as an npm module and save it to your package.json file as a dependency:
npm install --save email-syntax
Usage
Usage of validator is simple as 2 + 2. You need to import class and then use its "validate()" method.
Node.js
const EmailSyntax = require('email-syntax').EmailSyntax;
if (EmailSyntax.validate('[email protected]')){
console.log('This address is valid');
}
On server environment you can use additional methods:
- split(address) - Splits email address to local part and domain name
- extractFromQuotes(localPart) - Checks if quoted and extracts local part
- validateDomainName(domainName) - Validates domain name syntaxis
- validateLocalPart(localPart) - Validates local-part of address
- isValidIpAddress(domainName) - Checks if domain name is a valid ip address like 1.2.3.4
Angular 2/4
import { EmailSyntax } from 'email-syntax';
function isEmailValid(address): boolean{
return EmailSyntax.validate(address);
}
Tests
npm test