当前位置:网站首页>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>
边栏推荐
- Std:: vector batch import fast de duplication method
- Heap acwing 838 Heap sort
- [200 opencv routines] 100 Adaptive local noise reduction filter
- Interview questions for software testing - a collection of interview questions for large factories in 2022
- Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
- Dijkstra AcWing 850. Dijkstra finding the shortest circuit II
- Browser node event loop
- [opencv learning] [Canny edge detection]
- Structured data, semi-structured data and unstructured data
- C#修饰符
猜你喜欢

Interesting interview questions

应用LNK306GN-TL 转换器、非隔离电源

Linear DP acwing 897 Longest common subsequence

堆 AcWing 838. 堆排序

哈希表 AcWing 840. 模拟散列表

腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?

NTMFS4C05NT1G N-CH 30V 11.9A MOS管,PDF

js1day(输入输出语法,数据类型,数据类型转换,var和let区别)

Rust search server, rust quick service finding tutorial

VIM super practical guide collection of this one is enough
随机推荐
bellman-ford AcWing 853. Shortest path with side limit
绕过ObRegisterCallbacks需要驱动签名方法
Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
spfa AcWing 852. SPFA judgement negative ring
Jerry's watch stops ringing [article]
百款拿来就能用的网页特效,不来看看吗?
Post order traversal sequence of 24 binary search tree of sword finger offer
C#修饰符
Linear DP acwing 895 Longest ascending subsequence
moon
To bypass obregistercallbacks, you need to drive the signature method
难忘阿里,4面技术5面HR附加笔试面,走的真艰难真心酸
架构师必须了解的 5 种最佳软件架构模式
Typora+docsify quick start
Jerry's weather code table [chapter]
Rust search server, rust quick service finding tutorial
Oracle从入门到精通(第4版)
Floyd AcWing 854. Floyd求最短路
Variable, "+" sign, data type
Jerry's watch ringtone audition [article]