当前位置:网站首页>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>
边栏推荐
- ASP. Net MVC default configuration, if any, jumps to the corresponding program in the specified area
- JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
- [opencv learning] [common image convolution kernel]
- spfa AcWing 852. SPFA judgement negative ring
- Jerry's weather code table [chapter]
- 完全自主可控三维云CAD:CrownCAD便捷的命令搜索,快速定位所需命令具体位置。
- [error record] cannot open "XXX" because Apple cannot check whether it contains malware
- Hash table acwing 840 Simulated hash table
- bellman-ford AcWing 853. 有边数限制的最短路
- [opencv learning] [template matching]
猜你喜欢

Interesting interview questions

哈希表 AcWing 840. 模拟散列表

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

传感器 ADXL335BCPZ-RL7 3轴 加速度计 符合 RoHS/WEEE
![[opencv] [image gradient]](/img/37/1f366501e2b4e70ecee6365088167c.jpg)
[opencv] [image gradient]
![[opencv learning] [image filtering]](/img/4c/fe22e9cdf531873a04a7c4e266228d.jpg)
[opencv learning] [image filtering]

Linear DP acwing 899 Edit distance
![JDBC 预防sql注入问题与解决方法[PreparedStatement]](/img/32/f71f5a31cdf710704267ff100b85d7.png)
JDBC 预防sql注入问题与解决方法[PreparedStatement]

面渣逆袭:MySQL六十六问,两万字+五十图详解!有点六

阿里发布的Redis开发文档,涵盖了所有的redis操作
随机推荐
Interesting interview questions
国产免费数据仓库ETL调度自动化运维专家—TASKCTL
[200 opencv routines] 100 Adaptive local noise reduction filter
一些突然迸发出的程序思想(模块化处理)
ArrayList与LinkedList效率的对比
Rust search server, rust quick service finding tutorial
阿里发布的Redis开发文档,涵盖了所有的redis操作
JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
OLED screen driver based on stm32
. Net wechat message template push
[opencv learning] [contour detection]
Js10day (API phased completion, regular expression introduction, custom attributes, filtering sensitive word cases, registration module verification cases)
[opencv learning] [template matching]
Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
Js1day (input / output syntax, data type, data type conversion, VaR and let differences)
Hash table acwing 841 String hash
[opencv learning] [image filtering]
三面阿里,有惊无险成功拿到offer定级P7,只能说是真的难
百款拿来就能用的网页特效,不来看看吗?
Hundreds of web page special effects can be used. Don't you come and have a look?