RaptusBackend / middlewares /UserValidator.js
GitHub Actions
Initial commit
df72131
exports.validateUser = async function validateUser(data) {
var errors=false ;
// Validate Name
if (!data.Name) {
errors= "Name is required.";
return errors;
}
// Validate Email
if (!data.Email || !validateEmail(data.Email)) {
errors = "Email is invalid.";
return errors;
}
// Validate Password
if (!data.Password) {
errors = "Password is required.";
return errors;
}
// Validate RollNumber
if (!data.RollNumber || !/^\d{9}$/.test(data.RollNumber)) {
errors= "Roll number should be a 9-digit number.";
return errors;
}
// Validate PhoneNumber
if (!data.PhoneNumber || !/^\d{10}$/.test(data.PhoneNumber)) {
errors = "Phone number should be a 10-digit number.";
return errors;
}
// Validate Branch
if (!data.Branch) {
errors = "Branch is required.";
return errors;
}
// Validate Year
if (!data.Year) {
errors = "Year is required.";
return errors;
}
// Validate DiscordID
if (!data.DiscordID) {
errors = "Discord ID is required.";
return errors;
}
}
// Helper function to validate email format
function validateEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}