sane-email-validation
Advanced tools
Comparing version 1.0.0 to 1.1.0
exports = module.exports = isEmail; | ||
exports.isNotEmail = isNotEmail; | ||
@@ -22,1 +23,5 @@ var localAddr = /^[a-z0-9.!#$%&'*+\/=?^_`{|}~-]+$/i; | ||
} | ||
function isNotEmail( str ) { | ||
return !isEmail( str ) | ||
} |
@@ -1,2 +0,2 @@ | ||
Copyright 2014 Scott González http://scottgonzalez.com | ||
Copyright Scott González http://scottgonzalez.com | ||
@@ -3,0 +3,0 @@ Permission is hereby granted, free of charge, to any person obtaining |
{ | ||
"name": "sane-email-validation", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"author": "Scott González <scott.gonzalez@gmail.com> (http://scottgonzalez.com)", | ||
@@ -28,5 +28,5 @@ "description": "Sanely validate email addresses, based on HTML5's definition of email addresses", | ||
"devDependencies": { | ||
"dco": "0.0.1", | ||
"dco": "1.0.0", | ||
"nodeunit": "0.9.0" | ||
} | ||
} |
@@ -26,5 +26,20 @@ # Sane Email Validation | ||
### `isNotEmail()` | ||
An inverted check is also exposed. | ||
```js | ||
var isNotEmail = require( "sane-email-validation" ).isNotEmail; | ||
var email = "..."; | ||
if ( isNotEmail( email ) ) { | ||
console.log( email + " is not valid." ); | ||
} else { | ||
console.log( email + " is valid." ); | ||
} | ||
``` | ||
## License | ||
Copyright 2014 Scott González. Released under the terms of the MIT license. | ||
Copyright Scott González. Released under the terms of the MIT license. | ||
@@ -31,0 +46,0 @@ --- |
var isEmail = require( "../../index" ); | ||
var isNotEmail = require( "../../index" ).isNotEmail; | ||
@@ -37,7 +38,7 @@ exports.isEmail = { | ||
test.ok( isEmail( longLabel + longLabel + "@example.com" ), | ||
test.strictEqual( isEmail( longLabel + longLabel + "@example.com" ), true, | ||
"Should accept very long local address." ); | ||
test.ok( isEmail( "debt@" + longLabel + ".com" ), | ||
test.strictEqual( isEmail( "debt@" + longLabel + ".com" ), true, | ||
"Should accept 63 character domain labels." ); | ||
test.ok( isEmail( ".!#$%&'*+/=?^_`{|}~-a9@example.com" ), | ||
test.strictEqual( isEmail( ".!#$%&'*+/=?^_`{|}~-a9@example.com" ), true, | ||
"Should accept certain special characters in local address." ); | ||
@@ -47,1 +48,45 @@ test.done(); | ||
}; | ||
exports.isNotEmail = { | ||
"empty": function( test ) { | ||
test.expect( 1 ); | ||
test.strictEqual( isNotEmail( "" ), true, "Should not accept empty email." ); | ||
test.done(); | ||
}, | ||
"invalid": function( test ) { | ||
test.expect( 7 ); | ||
var longLabel = new Array( 65 ).join( "a" ); | ||
test.strictEqual( isNotEmail( "debt" ), true, | ||
"Cannot be local only." ); | ||
test.strictEqual( isNotEmail( "@example.com" ), true, | ||
"Cannot be domain only." ); | ||
test.strictEqual( isNotEmail( "debt@example" ), true, | ||
"Cannot have a domain with only one label." ); | ||
test.strictEqual( isNotEmail( "debt@-example.com" ), true, | ||
"Cannot start domain with a hyphen." ); | ||
test.strictEqual( isNotEmail( "debt@example-.com" ), true, | ||
"Cannot end domain with a hyphen." ); | ||
test.strictEqual( isNotEmail( "debt@example!com" ), true, | ||
"Cannot contain special characters in domain." ); | ||
test.strictEqual( isNotEmail( "debt@" + longLabel + ".com" ), true, | ||
"Cannot contain domain label >63 characters." ); | ||
test.done(); | ||
}, | ||
"valid": function( test ) { | ||
test.expect( 3 ); | ||
var longLabel = new Array( 64 ).join( "a" ); | ||
test.strictEqual( isNotEmail( longLabel + longLabel + "@example.com" ), false, | ||
"Should accept very long local address." ); | ||
test.strictEqual( isNotEmail( "debt@" + longLabel + ".com" ), false, | ||
"Should accept 63 character domain labels." ); | ||
test.strictEqual( isNotEmail( ".!#$%&'*+/=?^_`{|}~-a9@example.com" ), false, | ||
"Should accept certain special characters in local address." ); | ||
test.done(); | ||
} | ||
}; |
10638
150
48