Comments (4)
只能输入零和非零开头的数字
^(0|[1-9][0-9]*)$
from blog.
国内手机号验证
^1(3|4|5|6|7|8|9)\d{9}$
from blog.
身份证号码校验方法
/**
* 校验身份证是否合法
* @param {String} no 身份证号码字符串
*/
function validateIdNo(no) {
if (no.length < 18) {
return {
status: 'error',
msg: '身份证号码长度不能小于18位'
}
}
// 最后一位的校验
const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
const marks = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
let sum = 0
for (let i = 0; i < 17; i++) {
sum += Number(no[i]) * weights[i]
}
const lastCode = marks[sum % 11]
if (lastCode === no[no.length - 1]) {
return {
status: 'success',
msg: '身份证号码校验通过'
}
}
return {
status: 'error',
msg: '身份证号码校验不通过'
}
}
from blog.
银行卡校验方法
/**
* 银行卡Luhn校验算法
* https://en.wikipedia.org/wiki/Luhn_algorithm
* @param {String} bankCardNo 银行卡号
*/
function validateBankCardNo(bankCardNo) {
// 字符串化并去除中间或者前后的空格
const strDigits = `${bankCardNo}`.replace(/[\D]/g, '')
// 银行卡号必须为12-19位数字
if (!/^\d{12,19}$/.test(strDigits)) {
return {
status: 'error',
msg: '银行卡号码长度需在12-19位之间'
}
}
let sum = 0
const len = strDigits.length
for (let i = len - 1; i > -1; i--) {
const digit = parseInt(strDigits[i], 10) * ((len - i) % 2 === 0 ? 2 : 1)
if (digit < 10) {
sum += digit
} else {
sum += (digit % 10) + parseInt(digit / 10, 10)
}
}
if (sum % 10 === 0) {
return {
status: 'success',
msg: '银行卡号码校验通过'
}
} else {
return {
status: 'error',
msg: '银行卡号码校验不通过'
}
}
}
from blog.
Related Issues (19)
- 构建自己的 GLSL 绘图器 - 2d 版
- webGL二维有向距离场(SDF)及布尔运算 HOT 1
- webGL入门-绘制第一个三角形
- 自己动手开发一个 markdown 转微信文章
- 简单解析虚拟DOM
- Vue组件扩展及权限管理的实现技巧
- 使用 CSS 绘制三角形
- Nginx 简单配置和使用
- webpack按需加载配置和babel编译
- webpack 区分环境使用CDN以及HtmlWebpackPlugin插件的编写
- 面试常问题
- 使用 Mpvue 开发小程序总结
- JS 知识汇总-持续更新
- webGL 学习总结 - 持续更新
- 工作知识点记录
- React**要点
- Mapbox 入门及基础知识
- qcharts 介绍与推荐 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.