当前位置:网站首页>JS generates 4-digit verification code
JS generates 4-digit verification code
2022-07-02 13:05:00 【Gongsun yuaner】
Pre knowledge :
common ASCII The size rule of the code :0~9<A~Z<a~z
- Numbers are smaller than letters . Such as “7”<“F”;
- Numbers 0 More than numbers 9 smaller , And press 0 To 9 The order is increasing . Such as “3"<"8”;
- Letter A Than letters Z smaller , And press A To Z The order is increasing . Such as “A"<“Z”;
- The upper case of the same letter is smaller than the lower case 32. Such as “A”<"a”.
A few common letters ASCII Code size :“A” by 65;“a" by 97;“0” by 48
demand :
Implement a generated random 4 Function of bit verification code , Contains figures 、 Letter case
Code :
<script>
// '0' - '9' : 48~57
// 'A' - 'Z' : 65~90
// 'a' - 'z' : 97~122
// Write a random function , This function can generate numbers in the specified range
const getRandom = (min,max)=>{
return Math.floor(Math.random()*(max-min+1)) + min
}
const getVerifyCode = ()=>{
let str = ''
// 3. Cycle four times
for(let i=0;i<4;i++){
// 1. Get the corresponding character ASCII Code value
const ascii = getRandom(48,122)
if((ascii>57&&ascii<65)||(ascii>90&&ascii<97)){
i--
continue
}
// 2. adopt ASCII Code value to the corresponding string :String.fromCharCode(ASCII value )
const c = String.fromCharCode(ascii)
// 4. Splice together
str += c
}
// 5. Return results
return str
}
console.log(' The verification code is :', getVerifyCode())
</script>
边栏推荐
- Mongodb redis differences
- [opencv learning] [Canny edge detection]
- . Net wechat message template push
- 3 a VTT terminal regulator ncp51200mntxg data
- spfa AcWing 851. spfa求最短路
- JS iterator generator asynchronous code processing promise+ generator - > await/async
- 8A 同步降压稳压器 TPS568230RJER_规格信息
- Window10 upgrade encountered a big hole error code: 0xc000000e perfect solution
- 上手报告|今天聊聊腾讯目前在用的微服务架构
- Get started REPORT | today, talk about the microservice architecture currently used by Tencent
猜你喜欢
Jerry's watch delete alarm clock [chapter]
Linear DP acwing 895 Longest ascending subsequence
3 A VTT端接 稳压器 NCP51200MNTXG资料
Dijkstra AcWing 850. Dijkstra求最短路 II
How can attribute mapping of entity classes be without it?
堆 AcWing 839. 模拟堆
Async/await asynchronous function
[200 opencv routines] 100 Adaptive local noise reduction filter
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
阿里发布的Redis开发文档,涵盖了所有的redis操作
随机推荐
8A Synchronous Step-Down regulator tps568230rjer_ Specification information
js4day(DOM开始:获取DOM元素内容,修改元素样式,修改表单元素属性,setInterval定时器,轮播图案例)
To bypass obregistercallbacks, you need to drive the signature method
VIM super practical guide collection of this one is enough
Typora+docsify quick start
Sensor adxl335bcpz-rl7 3-axis accelerometer complies with rohs/weee
架构师必须了解的 5 种最佳软件架构模式
模数转换器(ADC) ADE7913ARIZ 专为三相电能计量应用而设计
The coloring method determines the bipartite graph acwing 860 Chromatic judgement bipartite graph
接口测试面试题目,你都会了吗?
Browser storage scheme
基于STM32的OLED 屏幕驱动
JDBC prevent SQL injection problems and solutions [preparedstatement]
日本赌国运:Web3.0 ,反正也不是第一次失败了!
Async/await asynchronous function
Jerry's watch stops ringing [article]
Js2day (also i++ and ++i, if statements, ternary operators, switch, while statements, for loop statements)
Js5day (event monitoring, function assignment to variables, callback function, environment object this, select all, invert selection cases, tab column cases)
Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
Execute any method of any class through reflection