express-validation-map
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -5,3 +5,4 @@ function isRequired(value) { | ||
function isName(value){ | ||
function isName(value = undefined){ | ||
if( value === undefined) return true; | ||
const regName = new RegExp('^[a-zа-я-]+$', 'i'); | ||
@@ -11,3 +12,10 @@ return regName.test(value); | ||
function isEmail(value) { | ||
function isNameWithSpace(value = undefined) { | ||
if( value === undefined) return true; | ||
const regName = new RegExp('^[a-zа-я- ]+$', 'i'); | ||
return regName.test(value); | ||
} | ||
function isEmail(value = undefined) { | ||
if( value === undefined) return true; | ||
const regEmail = new RegExp('^[0-9a-z-_\\+.]+\\@([0-9a-z-]{2,}\\.)+[a-z]{2,}$', 'i'); | ||
@@ -17,11 +25,63 @@ return regEmail.test(value); | ||
function isInteger(value) { | ||
return Number.isInteger(+value); | ||
function isInteger(value = undefined ) { | ||
if( value === undefined) return true; | ||
return Number(value) === +value && +value % 1 === 0 && value !== ''; | ||
} | ||
function isDecimal(value = undefined ) { | ||
if( value === undefined) return true; | ||
console.log('isDecimal', value ); | ||
return Number(value) === +value && +value % 1 !== 0 && value !== ''; | ||
} | ||
function isRangeNumber(min, max) { | ||
return value => +min <= +value && +max >= +value; | ||
return value => { | ||
if( value === undefined) return true; | ||
return +min <= +value && +max >= +value && value !== ''; | ||
} | ||
} | ||
function isPhoneUSA(value = undefined) { | ||
if( value === undefined) return true; | ||
const regPhone = new RegExp('^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$', 'im'); | ||
return regPhone.test(value); | ||
} | ||
function isWebsite(value = undefined) { | ||
if( value === undefined) return true; | ||
const regWebsite = new RegExp('^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$', 'gm'); | ||
return regWebsite.test(value); | ||
} | ||
function isStreetAddressUSA ( value = undefined) { | ||
if( value === undefined) return true; | ||
const regStreet = new RegExp('^\d+\s[A-z]+\s[A-z]+', 'gi'); | ||
return regStreet.test(value); | ||
} | ||
function isZipAddressUSA( value = undefined) { | ||
if( value === undefined) return true; | ||
const regZip = new RegExp('^[0-9]{5}(?:-[0-9]{4})?$', 'gi'); | ||
return regZip.test(value); | ||
} | ||
function isStateAddressUSA( value = undefined) { | ||
if( value === undefined) return true; | ||
const regState = new RegExp('([A-Z]{2})', 'g'); | ||
return regState.test(value); | ||
} | ||
function isUUID( value = undefined) { | ||
if( value === undefined) return true; | ||
const regUUID = new RegExp('[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}', 'gm'); | ||
return regUUID.test(value); | ||
} | ||
module.exports = { | ||
@@ -32,3 +92,11 @@ isRequired, | ||
isName, | ||
isRangeNumber | ||
isNameWithSpace, | ||
isRangeNumber, | ||
isPhoneUSA, | ||
isWebsite, | ||
isStreetAddressUSA, | ||
isZipAddressUSA, | ||
isStateAddressUSA, | ||
isDecimal, | ||
isUUID | ||
} |
{ | ||
"name": "express-validation-map", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/Valentinishe/express-validation-map", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10002
146