标题这是一个表单验证的纯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;
}
}
}