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

122
Views
Problema de expresión regular con JavaScript

Al igual que el título, tengo un problema con el siguiente código

 function checkPhone(phone){ var reg = "/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im"; var result=phone.match(reg); if (result) { console.log("(true)phone "+phone); return (true) } else { console.log("(error)phone "+phone); } }
 <div class="form-group"> <label >Numero di Telefono</label><br> <input type="text" id="phone" onchange="checkPhone(this.value)" placeholder="Insert phone number"> </div>

Independientemente de lo que intente poner en phone , dará como resultado "(error)phone "+phone . También lo he probado en línea y funciona.

¿Cómo puedo solucionar el problema?

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

0

El problema es que tiene comillas alrededor de la expresión regular. Prueba esto:

 function checkPhone(phone){ var reg = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im; var result=phone.match(reg); if (result) { console.log("(true)phone "+phone); return (true) } else { console.log("(error)phone "+phone); } }
 <div class="form-group"> <label >Numero di Telefono</label><br> <input type="text" id="phone" onchange="checkPhone(this.value)" placeholder="Insert phone number"> </div>

Consulte Expresiones regulares en MDN .

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!