当前位置:网站首页>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>
边栏推荐
- The redis development document released by Alibaba covers all redis operations
- Interview questions for software testing - a collection of interview questions for large factories in 2022
- Ali was killed by two programming problems at the beginning, pushed inward again, and finally landed (he has taken an electronic offer)
- 3 A VTT端接 稳压器 NCP51200MNTXG资料
- Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
- Linear DP acwing 897 Longest common subsequence
- Traverse entrylist method correctly
- Structured data, semi-structured data and unstructured data
- Linear DP acwing 898 Number triangle
- PXE installation UOS prompt NFS over TCP not available from 10 x.x.x
猜你喜欢

Heap acwing 839 Simulated reactor

JS8day(滚动事件(scroll家族),offset家族,client家族,轮播图案例(待做))

How can attribute mapping of entity classes be without it?

Analog to digital converter (ADC) ade7913ariz is specially designed for three-phase energy metering applications

Unity SKFramework框架(十七)、FreeCameraController 上帝视角/自由视角相机控制脚本

Variable, "+" sign, data type

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

Redis transaction mechanism implementation process and principle, and use transaction mechanism to prevent inventory oversold

日本赌国运:Web3.0 ,反正也不是第一次失败了!
![[200 opencv routines] 100 Adaptive local noise reduction filter](/img/89/9e9b667dd28cb25af005b6028ef26c.jpg)
[200 opencv routines] 100 Adaptive local noise reduction filter
随机推荐
Analog to digital converter (ADC) ade7913ariz is specially designed for three-phase energy metering applications
Jerry's watch ringtone audition [article]
[opencv learning] [image filtering]
腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
spfa AcWing 852. spfa判断负环
spfa AcWing 852. SPFA judgement negative ring
基于STM32的OLED 屏幕驱动
JDBC prevent SQL injection problems and solutions [preparedstatement]
Visual studio efficient and practical extension tools and plug-ins
8 examples of using date commands
Oracle from entry to mastery (4th Edition)
NTMFS4C05NT1G N-CH 30V 11.9A MOS管,PDF
Hash table acwing 841 String hash
面渣逆袭:MySQL六十六问,两万字+五十图详解!有点六
moon
Typora+docsify quick start
Js1day (input / output syntax, data type, data type conversion, VaR and let differences)
Ltc3307ahv meets EMI standard, step-down converter qca7005-al33 phy
Mui WebView down refresh pull-up load implementation
Get started REPORT | today, talk about the microservice architecture currently used by Tencent