当前位置:网站首页>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>
边栏推荐
- Linear DP acwing 899 Edit distance
- js1day(輸入輸出語法,數據類型,數據類型轉換,var和let區別)
- bellman-ford AcWing 853. Shortest path with side limit
- 嵌入式软件开发
- 正确遍历EntryList方法
- Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)
- Variable, "+" sign, data type
- 日本赌国运:Web3.0 ,反正也不是第一次失败了!
- Unity SKFramework框架(十九)、POI 兴趣点/信息点
- Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures in detail! A little six
猜你喜欢

C#修饰符

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

LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
![[opencv learning] [image filtering]](/img/4c/fe22e9cdf531873a04a7c4e266228d.jpg)
[opencv learning] [image filtering]

Floyd AcWing 854. Floyd finds the shortest path
![[opencv learning] [template matching]](/img/4c/7214329a34974c59b4931c08046ee8.jpg)
[opencv learning] [template matching]

Dijkstra AcWing 850. Dijkstra finding the shortest circuit II

Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.

Unforgettable Ali, 4 skills, 5 hr additional written tests, it's really difficult and sad to walk

JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)
随机推荐
Browser storage scheme
Linear DP acwing 897 Longest common subsequence
[opencv learning] [common image convolution kernel]
Hash table acwing 841 String hash
哈希表 AcWing 840. 模拟散列表
Get started REPORT | today, talk about the microservice architecture currently used by Tencent
Ntmfs4c05nt1g N-ch 30V 11.9a MOS tube, pdf
三面阿里,有惊无险成功拿到offer定级P7,只能说是真的难
About the loading of layer web spring layer components, the position of the layer is centered
架构师必须了解的 5 种最佳软件架构模式
Typora+docsify quick start
Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment
Linear DP acwing 895 Longest ascending subsequence
Hundreds of web page special effects can be used. Don't you come and have a look?
Variable, "+" sign, data type
Jerry's weather code table [chapter]
Traverse entrylist method correctly
Window10 upgrade encountered a big hole error code: 0xc000000e perfect solution
Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)
Browser node event loop