当前位置:网站首页>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>
边栏推荐
- Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
- Js4day (DOM start: get DOM element content, modify element style, modify form element attributes, setinterval timer, carousel Map Case)
- 接口测试面试题目,你都会了吗?
- Linear DP acwing 896 Longest ascending subsequence II
- JDBC prevent SQL injection problems and solutions [preparedstatement]
- [opencv learning] [contour detection]
- spfa AcWing 852. spfa判断负环
- Domestic free data warehouse ETL dispatching automation operation and maintenance expert taskctl
- 阿里发布的Redis开发文档,涵盖了所有的redis操作
- Ltc3307ahv meets EMI standard, step-down converter qca7005-al33 phy
猜你喜欢
[opencv learning] [template matching]
Jerry's watch delete alarm clock [chapter]
Unforgettable Ali, 4 skills, 5 hr additional written tests, it's really difficult and sad to walk
面渣逆袭:MySQL六十六问,两万字+五十图详解!有点六
8 examples of using date commands
JS8day(滚动事件(scroll家族),offset家族,client家族,轮播图案例(待做))
js4day(DOM开始:获取DOM元素内容,修改元素样式,修改表单元素属性,setInterval定时器,轮播图案例)
堆 AcWing 838. 堆排序
[opencv] [image gradient]
国产免费数据仓库ETL调度自动化运维专家—TASKCTL
随机推荐
堆 AcWing 839. 模拟堆
3 A VTT端接 稳压器 NCP51200MNTXG资料
[200 opencv routines] 100 Adaptive local noise reduction filter
Unity SKFramework框架(十八)、RoamCameraController 漫游视角相机控制脚本
The UVM Primer——Chapter2: A Conventional Testbench for the TinyALU
Redis bloom filter
Jerry's weather code table [chapter]
About asp Net MVC project in local vs running response time is too long to access, the solution!
Jerry's watch ringtone audition [article]
Do you know all the interface test interview questions?
moon
Oracle from entry to mastery (4th Edition)
Jerry's watch gets the default ringtone selection list [article]
spfa AcWing 851. SPFA finding the shortest path
Interesting interview questions
8A Synchronous Step-Down regulator tps568230rjer_ Specification information
C#运算符
NTMFS4C05NT1G N-CH 30V 11.9A MOS管,PDF
Rust search server, rust quick service finding tutorial
基于STM32的OLED 屏幕驱动