当前位置:网站首页>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>
边栏推荐
- Js2day (also i++ and ++i, if statements, ternary operators, switch, while statements, for loop statements)
- Hash table acwing 841 String hash
- Domestic free data warehouse ETL dispatching automation operation and maintenance expert taskctl
- Unforgettable Ali, 4 skills, 5 hr additional written tests, it's really difficult and sad to walk
- [200 opencv routines] 100 Adaptive local noise reduction filter
- Ltc3307ahv meets EMI standard, step-down converter qca7005-al33 phy
- [error record] cannot open "XXX" because Apple cannot check whether it contains malware
- js3day(数组操作,js冒泡排序,函数,调试窗口,作用域及作用域链,匿名函数,对象,Math对象)
- moon
- Interesting interview questions
猜你喜欢
![[opencv learning] [contour detection]](/img/96/aaec61f137e4526c2c329e6fcfa1a2.jpg)
[opencv learning] [contour detection]

Linear DP acwing 898 Number triangle

Linear DP acwing 899 Edit distance

三面阿里,有惊无险成功拿到offer定级P7,只能说是真的难
![[opencv learning] [Canny edge detection]](/img/8b/37694ae2f0f13f829f3c033da0605e.jpg)
[opencv learning] [Canny edge detection]
![Jerry's watch time synchronization [chapter]](/img/64/a48772b4e503ae0a2d36fc292e4e0d.jpg)
Jerry's watch time synchronization [chapter]
![[error record] cannot open](/img/d3/0435ae698ad635be71729c7c047a22.jpg)
[error record] cannot open "XXX" because Apple cannot check whether it contains malware

3 a VTT terminal regulator ncp51200mntxg data

Interesting interview questions

C#运算符
随机推荐
Use MySQL events to regularly perform post seven world line tasks
Unforgettable Ali, 4 skills, 5 hr additional written tests, it's really difficult and sad to walk
Js4day (DOM start: get DOM element content, modify element style, modify form element attributes, setinterval timer, carousel Map Case)
Ntmfs4c05nt1g N-ch 30V 11.9a MOS tube, pdf
Obtain file copyright information
Typora+docsify quick start
Js6day (search, add and delete DOM nodes. Instantiation time, timestamp, timestamp cases, redrawing and reflow)
bellman-ford AcWing 853. Shortest path with side limit
Should I have a separate interface assembly- Should I have a separate assembly for interfaces?
Mui WebView down refresh pull-up load implementation
三面阿里,有惊无险成功拿到offer定级P7,只能说是真的难
哈希表 AcWing 841. 字符串哈希
Oracle从入门到精通(第4版)
West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
JS iterator generator asynchronous code processing promise+ generator - > await/async
阿里发布的Redis开发文档,涵盖了所有的redis操作
Js1day (syntaxe d'entrée / sortie, type de données, conversion de type de données, Var et let différenciés)
Jerry's watch stops ringing [article]
Sensor adxl335bcpz-rl7 3-axis accelerometer complies with rohs/weee
[opencv learning] [template matching]