Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

108
Vistas
React: Always Keep the first four characters onchange

So basically I have an input component for phone numbers. I am using the react native phone input library, so the international code is added by default. I want to set the input change in such a way that the international code +234 never gets deleted with the back button. I believe regex is the way to go using let regex = /[^+234]/g to match the start but I don't know how to proceed next.

So basically if a user types any number in, +234 is added by default to the beginning of phoneNumber. With the current design of the library, the +234 prefix gets deleted when the user deletes the number . What I want is for the +234 to be kept no matter how much the user deletes

CODE

 const onChangePhoneNumberHandler = (phoneNumber: string) => {
        setPhoneNumber(phoneNumber)
        showMessage({ text: ``});
        
    }

    <PhoneInput 
         value={phoneNumber}
        onChangePhoneNumber={onChangePhoneNumberHandler}
    />
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

const onChangePhoneNumberHandler = (phoneNumber?: string) => {
    const newNumber = phoneNumber?.includes("+234") ? phoneNumber : "+234"
    setPhoneNumber(newNumber)
    showMessage({ text: ``});
    
}

Might wanna fine tune the logic part but that is a quick solutin

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda