npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

easy-regexp

v1.0.1

Published

前端编写代码以及表单验证常用正则表达式验证和提取

Downloads

8

Readme

使用方法

安装

    npm install easy-regexp

导入

    const easyRegexp = require('easy-regexp');

功能函数

用户名校验

输入:
用户名name
用户名位数下限start(默认为6)
用户名位数下线end(默认为15)
是否可以使用特殊字符“-”或者“_”specialPermit(默认为true)
是否开启首字母不为特殊字符firstChar(默认为true)

示例

const easyRegexp = require('easy-regexp');
console.log(easyRegexp.nameReg('sd_s123',true,true));     //true
console.log(easyRegexp.nameReg('sd_s123',10,15,true,true));     //false

密码校验

输入:
密码password
用户名位数下限start(默认为6)
用户名位数下线end(默认为30)
是否需要包括至少1个大写字母bigLetter(默认为true)
是否需要包括至少1个小写字母smallLetter(默认为true)
是否需要包括至少1个数字number(默认为true)
是否需要包括至少1个特殊字符spesialChar(默认为true)

示例

const easyRegexp = require('easy-regexp');
console.log(easyRegexp.passwordReg('Mwxds89!'));     //true
console.log(easyRegexp.passwordReg('sds123'));     //false

邮箱匹配

名称允许汉字、字母、数字,下划线,中划线,域名可以有数字、字母、下划线、中划线组成

示例

const easyRegexp = require('easy-regexp');
console.log(easyRegexp.emailReg('[email protected]'));     //true
console.log(easyRegexp.emailReg('sdfl!&*@qq.com'));     //false

手机号匹配

示例

const easyRegexp = require('easy-regexp');
console.log(easyRegexp.phoneReg('18973682949'));     //true
console.log(easyRegexp.phoneReg('14374927530'));     //false

二代身份证匹配

若匹配不成功返回false,匹配成功则从身份证中提取出生年月日

示例

const easyRegexp = require('easy-regexp');
if(easyRegexp.IDReg('441880199903060224')) {
    let [year,month,date] = easyRegexp.IDReg('441880199922060224');
    console.log(year);  //1999
    console.log(month);  //03
    console.log(date);   //06
}
else {
    console.log("身份证号码匹配失败!")
}

html标签匹配

匹配并提取html标签的属性及对应属性值,输出为对象 注意:简写属性也可以提取成功!

示例

const easyRegexp = require('easy-regexp');
console.log(easyRegexp.htmlAttrReg('<img alt="" src="static/logo.png"/>'));     //Object { alt: "", src: "static/logo.png" }
console.log(easyRegexp.htmlAttrReg('<input name="input" disabled/>'));     //Object { name: "input", disabled: "true" }

16进制颜色匹配

可支持三位十六进制颜色缩写

示例

const easyRegexp = require('easy-regexp');
console.log(easyRegexp.colorReg('#efefef'));     //true
console.log(easyRegexp.colorReg('#eee'));     //true

url匹配

匹配url并依次输出协议、域名、端口、路径、请求参数(输出undefined即该项为空)

示例

const easyRegexp = require('easy-regexp');
console.log(easyRegexp.urlReg('https://www.baidu.com:8080/home/api?id=123&index=35'));     //Array(5) [ "https", "www.baidu.com", "8080", "/home/api", Object { id: "123", index: "35" } ]
console.log(easyRegexp.urlReg('https://www.baidu.com/home/api?id=123&index=35'));     //Array(5) [ "https", "www.baidu.com", undefined, "/home/api", Object { id: "123", index: "35" } ]