NPM酷库,每天两分钟,了解一个流行的NPM库。在开发过程中,我们经常需要对用户输入的数据进行各种验证,比如判断邮件格式是否合法,判断URL是否合法等,我们可以找不同的npm包来验证不同的数据。今天给大家介绍一个验证工具合集:validator,里面包含了很多常用的验证器。使用validator,我们可以直接requirevalidator,这样我们就引入了所有的validator集合。constvalidator=require('验证器');validator.isEmail('foo@bar.com');//=>true我们也可以根据需要要求单独的验证器。constisEmail=require('validator/lib/isEmail');isEmail('foo@bar.com');//=>truevalidatorlistvalidatordescriptioncontains(str,seed)checkcontainsequals(str,comparison)检查相等性isAfter(str[,date])验证给定时间字符串是否在指定日期之后isAlpha(str[,locale])检查字符串是否只包含字母字符isAlphanumeric(str[,locale])检查字符串是否只包含字母和数字isAscii(str)检查字符串是否只包含ASCII字符isBase64(str)检查它是否是一个Base64stringisBefore(str[,date])验证给定时间字符串是否在指定日期之前isBoolean(str)检查字符串是否为布尔值isByteLength(str,options)检查字符串长度是否在区间内由options给出,options默认为{min:0,max:undefined}.isCreditCard(str)检查字符串是否为信用卡号isCurrency(str,options)检查字符串是否为有效的货币值isDataURI(str)检查字符串是否为数据URIisDecimal(str,options)检查它是否为十进制数isDivisibleBy(str,number)检查一个数字是否可以被另一个数字分隔str)检查字符串是否为空isFQDN(str[,options])检查字符串是否为有效域名isFloat(str[,options])检查字符串是否为小数isFullWidth(str)检查字符串是否包含Unicode全-widthcharactersisHalfWidth(str)检查字符串是否包含Unicode半角字符isHash(str,algorithm)检查字符串是否为指定算法的HASH摘要,算法包括['md4','md5','sha1','sha256','sha384','sha512','ripemd128','ripemd160','tiger128','tiger160','tiger192','crc32','crc32b']isHexColor(str)是十六进制颜色值isHexadecimal(str)是十六进制数isIP(str[,version])检查字符串是否为IPisISBN(str[,version])检查字符串是否为ISBN书号isISSN(str[,options])检查字符串是否为ISSN杂志号isISIN(str)检查字符串是否为ISIN股票代码isISO8601(str)检查字符串是否为ISO8601格式时间isISO31661Alpha2(str)检查字符串是否为ISO3166-1alpha-2国家代码isISRC(str)检查字符isIn(str,values)检查字符串是否为数组中允许的值isInt(str[,options])检查字符串是否为整数isJSON(str)检查字符串是否为JSON字符串isLatLong(str)检查字符串是否为纬度andlongitudeisLength(str,options)检查字符串的长度isLowercase(str)检查字符串是否为小写isMACAddress(str)检查字符串是否为MAC地址isMD5(str)检查字符串是否为MD5HASHisMimeType(str)检查字符串是否为MIMEisMobilePhone(str,locale)检查字符串是否为合法手机号码isMongoId(str)检查字符串是否为MongoDBObjectIDisMultibyte(str)检查字符串是否包含多字节字符isNumeric(str)检查字符串是否为数字isPort(str)检查字符串是否为有效端口号isPostalCode(str,locale)检查字符串是否为邮政编码isSurrogatePair(str)检查字符串是否包含UTF-16扩展编码charisURL(str[,options])检查字符串是否为URL地址isUUID(str[,version])检查字符串是否为UUIDisUppercase(str)检查字符串是否为大写isVariableWidth(str)检查字符串是否同时包含全角和半角字符isWhitelisted(str,chars)检查字符串是否为白名单字符matches(str,pattern[,modifiers])检查字符串是否匹配指定的正则引用https://github.com/chriso/val...
