Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我有更好的正则: 身份证号, 支持1/2代(15位/18位数字) #55

Closed
Airkro opened this issue Dec 27, 2019 · 3 comments
Closed

Comments

@Airkro
Copy link

Airkro commented Dec 27, 2019

- /(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/
+ /(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}([\dXx])$)/

用字符组代替多选结构,可以提升性能

@any86
Copy link
Owner

any86 commented Dec 27, 2019

好的十分感谢, 稍后修改, 要不要提个pr参与下?

@Airkro
Copy link
Author

Airkro commented Dec 27, 2019

事实上我发现 eslint-plugin-unicorn 可以优化正则,这个issues也来自于此,我在考虑要不要提个统一的PR 将它集成进项目。

https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/regex-shorthand.md

不过它的优化不是绝对可靠的,需要人工审核

@any86
Copy link
Owner

any86 commented Dec 27, 2019

我有项目里有测试脚本, 可以简答测试一下, 提交后action会执行test
https://github.com/any86/any-rule/blob/master/__test__/rule.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants