gpt4 book ai didi

javascript - req.body 检查是否包含特定字符

转载 作者:行者123 更新时间:2023-12-03 03:49:41 26 4
gpt4 key购买 nike

在我的注册页面上,我使用 body-parser 来处理 req.body.username。如何让它检查特定字符,如果找到,则拒绝注册表单?基本上不允许用户创建包含以下字符的用户名:?

护照.js:

   passport.use('local-signup', new LocalStrategy({
usernameField: 'username',
passwordField: 'password',
gameusernameField: 'username',
nicknameField: 'nickname',
passReqToCallback: true
},

function(req, username, password, done) {

// here you read from req
const email = req.body.email;
const nickname = req.body.nickname;
newUserMysql.email = email;
newUserMysql.password = password;
newUserMysql.username = username;
newUserMysql.nickname = nickname;

服务器.js:

//For BodyParser
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(flash());

// For Passport
app.use(session({
secret: 'keyboard cat',
resave: true,
saveUninitialized: true
})); // session secret
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions

最佳答案

if (req.body.username.indexOf('?') > -1) {
//reject
} else {
//accept and continue
}

关于javascript - req.body 检查是否包含特定字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45222951/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com