当前位置:网站首页>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>
边栏推荐
- [error record] cannot open "XXX" because Apple cannot check whether it contains malware
- 完全自主可控三维云CAD:CrownCAD便捷的命令搜索,快速定位所需命令具体位置。
- js1day(輸入輸出語法,數據類型,數據類型轉換,var和let區別)
- Redis sentinel mechanism and configuration
- Ltc3307ahv meets EMI standard, step-down converter qca7005-al33 phy
- Mobile layout (flow layout)
- Js2day (also i++ and ++i, if statements, ternary operators, switch, while statements, for loop statements)
- Structured data, semi-structured data and unstructured data
- How can attribute mapping of entity classes be without it?
- About asp Net MVC project in local vs running response time is too long to access, the solution!
猜你喜欢

阿里初面被两道编程题给干掉,再次内推终上岸(已拿电子offer)

Interval DP acwing 282 Stone merging

Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))

3 A VTT端接 稳压器 NCP51200MNTXG资料

Js3day (array operation, JS bubble sort, function, debug window, scope and scope chain, anonymous function, object, Math object)

Dijkstra AcWing 850. Dijkstra求最短路 II

JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
![[opencv learning] [Canny edge detection]](/img/8b/37694ae2f0f13f829f3c033da0605e.jpg)
[opencv learning] [Canny edge detection]

Browser storage scheme

js5day(事件监听,函数赋值给变量,回调函数,环境对象this,全选反选案例,tab栏案例)
随机推荐
js1day(輸入輸出語法,數據類型,數據類型轉換,var和let區別)
Hash table acwing 840 Simulated hash table
Wechat official account payment prompt MCH_ ID parameter format error
Structured data, semi-structured data and unstructured data
Redis introduction, scenario and data type
Browser storage scheme
Obtain file copyright information
Jerry's watch gets the default ringtone selection list [article]
完全自主可控三维云CAD:CrownCAD便捷的命令搜索,快速定位所需命令具体位置。
About the loading of layer web spring layer components, the position of the layer is centered
Modular commonjs es module
Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment
Mongodb redis differences
Jerry's watch ringtone audition [article]
基于STM32的OLED 屏幕驱动
JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)
Floyd AcWing 854. Floyd求最短路
[opencv learning] [common image convolution kernel]
Jerry's watch reads the alarm clock [chapter]
[opencv learning] [image filtering]