当前位置:网站首页>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>
边栏推荐
- C#运算符
- js5day(事件监听,函数赋值给变量,回调函数,环境对象this,全选反选案例,tab栏案例)
- 腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
- Redis sentinel mechanism and configuration
- Direct control PTZ PTZ PTZ PTZ camera debugging (c)
- Interval DP acwing 282 Stone merging
- [opencv learning] [common image convolution kernel]
- 哈希表 AcWing 840. 模拟散列表
- Sensor adxl335bcpz-rl7 3-axis accelerometer complies with rohs/weee
- Linear DP acwing 897 Longest common subsequence
猜你喜欢
Execute any method of any class through reflection
C operator
Five best software architecture patterns that architects must understand
Js3day (array operation, JS bubble sort, function, debug window, scope and scope chain, anonymous function, object, Math object)
Heap acwing 839 Simulated reactor
Unity SKFramework框架(十七)、FreeCameraController 上帝视角/自由视角相机控制脚本
The redis development document released by Alibaba covers all redis operations
NTMFS4C05NT1G N-CH 30V 11.9A MOS管,PDF
Package management tools
模数转换器(ADC) ADE7913ARIZ 专为三相电能计量应用而设计
随机推荐
Hundreds of web page special effects can be used. Don't you come and have a look?
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
Rust语言文档精简版(上)——cargo、输出、基础语法、数据类型、所有权、结构体、枚举和模式匹配
Redis sentinel mechanism and configuration
哈希表 AcWing 841. 字符串哈希
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
Domestic free data warehouse ETL dispatching automation operation and maintenance expert taskctl
Jerry's watch gets the default ringtone selection list [article]
Jerry's watch delete alarm clock [chapter]
Interview questions for software testing - a collection of interview questions for large factories in 2022
Jerry's watch reads the alarm clock [chapter]
JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)
Browser node event loop
上海交大教授:何援军——包围盒(包容体/包围盒子)
Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
Jerry's watch modifies the alarm clock [chapter]
js4day(DOM开始:获取DOM元素内容,修改元素样式,修改表单元素属性,setInterval定时器,轮播图案例)
Ruby: how to copy variables without pointing to the same object- Ruby: how can I copy a variable without pointing to the same object?
自主可控三维云CAD:CrownCAD赋能企业创新设计
Should I have a separate interface assembly- Should I have a separate assembly for interfaces?