Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
No se puede leer la propiedad 'emailAddressValidation' de undefined

Solo estoy aprendiendo el nodo con el patrón MVC. Hice una clase de validación para validar los datos del usuario.

 class UserValidation { constructor() {} emailAddressValidation(email) { console.log(email); const regularExpression = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return regularExpression.test(email.toLowerCase()); } passwordValidation(password) { const regularExpression = /^(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{6,16}$/; } loginValidation(req, res, next) { const { email, password } = req.body; console.log(email); this.emailAddressValidation('addad'); // try { // if ( // this.emailAddressValidation(email) && // this.passwordValidation(password) // ) { // next(); // } else { // throw new Error( // 'All fields are Required.email,password.Password should be alpha numeric.' // ); // } // } catch (error) { // res.status(400).json({ err: 1, message: error.message }); // } } NewUserValidation(req, res, next) { const { name, email, password, address, skills } = req.body; try { if ( name && this.emailAddressValidation(email) && this.passwordValidation(password) && address.length > 0 && skills.length > 0 ) { next(); } else { throw new Error( 'All fields are required.Name,email,password,Address,Skills.Password should be alphanumeric.' ); } } catch (error) { res.status(400).json({ err: 1, message: error.message }); } } } export default new UserValidation();

Algo como esto y usarlo en mi ruta así

 router.post('/login', UserValidation.loginValidation);

Pero no sé por qué tengo este error.

TypeError: no se puede leer la propiedad 'emailAddressValidation' de undefined

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

this se referirá a una instancia de esa clase. Deberá inicializar un objeto de UserValidation y llamar a loginValidation en ese objeto. Algo como esto:

 const validator = UserValidation() router.post('/login', validator.loginValidation);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!