表单验证的纯js代码
作者:互联网
标题这是一个表单验证的纯js代码 提供观看 提供了简单的循环语句执行验证操作
执行代码段之前必须含有包文件并且引包!!!!
包文件私我:
包文件名字叫:node_modules
const readline = require(‘readline-sync’);
let user = [['zhangsan', '123'], ['lisi', '124']];
let islog = true;
while (islog) {
console.log('请输入1.注册2.登陆');
let opt = readline.question() - 0;
switch (opt) {
case 1://注册
{
console.log('请输入您的账号');
let usname = readline.question();
let isLogin = false;
for (let item of user) {
if (usname == item[0]) {
isLogin = true;
console.log('账号不可使用');
break;
}
}
if (!isLogin) {
console.log('请输入您的密码');
let Pwd = readline.question();
user.push([usname, Pwd]);
console.log('恭喜注册成功');
}
break;
}
case 2://登陆
{
console.log('请输入您的账号');
let usname = readline.question();
console.log('请输入您的密码');
let Pwd = readline.question();
let flage = false;
for (let item of user) {
if (item[0] == usname && item[1] == Pwd) {
console.log('登陆成功');
flage = true;
islog = false;
break;
}
}
if (!flage) {
console.log('查无此人');
}
break;
}
}
}
标签:console,log,验证,question,表单,item,let,readline,js 来源: https://blog.csdn.net/weixin_44736637/article/details/121962688