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

267
Views
Validar el número de teléfono comienza con 080, 081, 090, 070, 091

Quiero validar el prefijo del número de teléfono y la cantidad de dígitos.

El número de teléfono tendría 11 dígitos (solo numéricos). El prefijo debe comenzar con cualquiera de estos prefijos: 080, 081, 090, 091, 070 y el máximo es de 11 dígitos.

Coloqué un código de validación para validar los dígitos del número de teléfono usando el siguiente código en mi javascript y funciona bien.

 **Phone number 11 digits validation code below;**
 } else if (form.usercheck1.value.length<11 || form.usercheck1.value.length>11) { alert("phone number should be 11 digits!"); }

Pero necesito ayuda para validar el prefijo del teléfono. Cualquier ayuda sería apreciada.

mi código javascript completo a continuación;

 /* myScript.js */ function check(form) /*function to check userid & password*/ { /*the following code checkes whether the entered userid and password are matching*/ if (form.usercheck1.value == "1234" || form.usercheck1.value == "12345") { alert("An account already exist with this phone number! \nKindly login to proceed.") // displays error message } else if (form.usercheck1.value.length < 11 || form.usercheck1.value.length > 11) { alert("phone number should be 11 digits!"); } else { window.location.replace('https://www.google.com') /*opens the target page while Id & password matches*/ } } }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puedes usar este patrón: ^0([89][01]|70)\d{8}$

Esto verifica los prefijos y un total de 11 dígitos.

Nota: dijiste un máximo de 11 dígitos pero cuando leo tu código parece que quieres exactamente 11 dígitos, el patrón anterior funciona para exactamente 11 dígitos. si quieres llegar a un máximo de 11 dígitos, puedes usar esto: ^0([89][01]|70)\d{0,8}$

 <!DOCTYPE html> <html> <body> <form> <label for="phone_number">Phone number: </label> <input type="text" id="phone_number" name="phone_number" pattern="^0([89][01]|70)\d{8}$" title="Maximum length is 11 and Phone number must start with one of 080, 081, 090, 091 or 070 And must be all numeric"> <input type="submit" value="Submit"> </form> </body> </html>

about 4 years ago · Juan Pablo Isaza Report

0

¿Realmente necesitas usar expresiones regulares para esto?

¿Cuál de estos crees que es más fácil de entender?

 /^0(?:[89][01]|70)/.test(input) ['080', '081', '090', '070', '091'].includes(input.substring(0,3))

A menos que la lista sea muy larga y haya un patrón claro, optaría por no usar una expresión regular misteriosa aquí.

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!