app.post('/register', function(요청,응답){
console.log('전송왔음?')
db.collection('registerCount').findOne({name:"아이디번호"},function(에러, 결과){
var totalId = 결과.totalId;
db.collection('register').findOne({id: 요청.body.registerId},function(에러,결과){
console.log(요청.body.registerId)
console.log(결과)
//아이디 중복검사먼저 정규식
var engNum = /^[a-zA-Z0-9]*$/;
if(engNum.test(요청.body.registerId)){
if(결과 == null){
db.collection('register').insertOne({id: 요청.body.registerId, 비밀번호 : 요청.body.registerPw ,_id : totalId}, function(에러,결과){
db.collection('registerCount').updateOne({name : '아이디번호'},{ $inc :{totalId:1}},function(에러,결과){
if(에러){
return console.log(에러)
}else{
console.log('성공')
응답.send('<script>alert("회원가입을 축하합니다."); window.location.href = "/";</script>')
}
})
})
}else{
console.log('아이디 중복')
var registerNum = 1;
응답.json(registerNum)
}
}else{
var fail = 1;
응답.json(fail);
}
})
})
});
정규식 표현 검사할때 이렇게하는게 맞을까요 .. 이렇게하니까 정규식이 맞지않는데도 아이디 중복되었습니다라고 뜨더라고요 .
방법을 도저히 모르겠어서 질문해봅니다...