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

154
Views
solo los números regex JS funcionan en PC pero no en Android

Tengo una función que me permite usar solo números usando una expresión regular, la validación funciona bien en un navegador web de escritorio, pero cuando abro la aplicación en un dispositivo Android con Chrome, la validación se interrumpe y permite escribir letras y símbolos.

Estoy usando Angular y aquí está mi función:

 onlyNumber (event: KeyboardEvent) { let regex = /^\d*$/; const input = String.fromCharCode(event.key.charCodeAt(0)); if (!regex.test(input)) { event.preventDefault(); } }

o solo número y letra

 onlyNumberAndLetters = (event: KeyboardEvent) { let regex = /^[a-zA-Z0-9]*$/; const input = String.fromCharCode(event.key.charCodeAt(0)); if (!regex.test(input)) { event.preventDefault(); } }

usando

 <input type="text" class="form-control" minlength="8" maxlength="15" formControlName="secretNumber" (keypress)="onlyNumber($event)"> <input type="text" class="form-control" minlength="5" maxlength="25" formControlName="secretNumber2" (keypress)="onlyNumberAndLetters($event)">

PD: Estoy usando un campo de tipo de texto, porque era la forma más fácil de lograr la regla de longitud mínima y longitud máxima.

about 4 years ago · Juan Pablo Isaza
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!