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

reg-rules

v1.0.0

Published

Regular expressions commonly used in javascript

Downloads

1

Readme

Javascript常用正则大全

📦 快速安装

npm install reg-rules
yarn add reg-rules

📝文件类正则

图片

/\.(png|jpe?g|gif|svg|img|image|webp)$/i

import { isImage } from 'reg-rules'
isImage('test.png') // true

Word文档

/\.(doc[xm]?|dot[xm]?|wps|wpt)$/i

import { isWord } from 'reg-rules'
isWord('test.doc') // true

Excel表格

/\.(xls[xm]?|xlt[xm]?|csv|prn|dif|ett?)$/i

import { isExcel } from 'reg-rules'
isExcel('test.xls') // true

PPT演示

/\.(ppt[xm]?|pot[xm]?|pps[xm]?|dp[st])$/i

import { isPpt } from 'reg-rules'
isPpt('test.pptx') // true

PDF

/\.(pdf)$/i

import { isPdf } from 'reg-rules'
isPdf('test.pdf') // true

压缩包

/\.(rar|zip|7z|ace|uha|uda|bz|gz)$/i

import { isZip } from 'reg-rules'
isZip('test.zip') // true

音频文件

/\.(mp3|wav|mid|asf|mpg|tti)$/i

import { isMusic } from 'reg-rules'
isMusic('test.mp3') // true

视频文件

/\.(mp4|rmvb|avi|rm|wmv|mkv|mov)$/i

import { isVideo } from 'reg-rules'
isVideo('test.rm') // true

📋表单类正则

手机号码

/^(?:(?:\+|00)86)?1[3-9][0-9]{9}$/

import { isMobile } from 'reg-rules'
isMobile('13936126666') // true

座机号码

/^\d{3}-\d{8}|\d{4}-\d{7}$/

import { isTell } from 'reg-rules'
isTell('010-67866366') // true

数字

/^\d+$/

import { isNumber } from 'reg-rules'
isNumber('01067866366') // true

数字,带有小数点

/^\d+\.\d+$/

import { isNumberFloat } from 'reg-rules'
isNumberFloat('0.1067866366') // true

数字,可以带有一位小数点

/^\d+(\.\d{1})?$/

import { isNumberFloatOne } from 'reg-rules'
isNumberFloatOne('0.1') // true

数字,可以带有两位小数点

/^\d+(\.\d{2})?$/

import { isNumberFloatTwo } from 'reg-rules'
isNumberFloatTwo('0.11') // true

不能含有数字

/^\D*$/

import { isNoNumber } from 'reg-rules'
isNoNumber('test12345') // false
isNoNumber('test') // true

姓名-中文(毕加索全名54个字你造吗⁉️)

/^(?:[\u4e00-\u9fa5·|-]{2,72})$/

import { isName } from 'reg-rules'
isName('周杰伦') // true
isName('苏日勒和克·威武') // true
isName('苏日勒和克-威武') // true

姓名-英文

/(^[a-zA-Z][a-zA-Z\s]{0,233}[a-zA-Z]$)/

import { isNameEnglish } from 'reg-rules'
isNameEnglish('Daniel') // true
isNameEnglish('Chris Evans') // true

只有英文字母

/^[a-zA-Z]+$/

import { isEnglish } from 'reg-rules'
isEnglish('test') // true

不含有英文字母

/^[^A-Za-z]*$/

import { isNoEnglish } from 'reg-rules'
isNoEnglish('test') // false

邮箱

/^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/

import { isEmail } from 'reg-rules'
isEmail('[email protected]') // true

身份证号码

/^[1-9]\d{5}(?:18|19|20)\d{2}(?:0\d|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/

import { isIdCard } from 'reg-rules'
isIdCard('110101190103075978') // true

车牌号

/^(?:[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-HJ-NP-Z]{1}(?:(?:[0-9]{5}[DF])|(?:[DF](?:[A-HJ-NP-Z0-9])[0-9]{4})))|(?:[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9 挂学警港澳]{1})$/

import { isCarNumber } from 'reg-rules'
isCarNumber('浙A00001') // true
isCarNumber('浙AD00001') // true 新能源

邮政编码

/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/

import { isPostalCode } from 'reg-rules'
isPostalCode('310000') // true

用户名校验 4到18位(字母,数字,点,下划线,减号)

/^[a-zA-Z0-9._-]{4,18}$/

import { isUserName } from 'reg-rules'
isUserName('zheng_ao-jin.123') // true

微信号

/^[a-zA-Z][-_a-zA-Z0-9]{5,19}$/

import { isWeChat } from 'reg-rules'
isWeChat('zheng_ao-jin123') // true

QQ号

/^[1-9][0-9]{4,}$/

import { isQq } from 'reg-rules'
isQq('10000') // true

金额(支持千位分隔符、负数)

/^-?\d+(,\d{3})*(\.\d{1,2})?$/

import { isMoney } from 'reg-rules'
isMoney('1234,567,890') // true