Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
How can I add phone number validation for specific countries by regex? How can I use if statement for it?

inputRef is the number that I am entering into the input box. it only consists of numbers without country code. first of all I have to choose or type country code and it is gonna be done by . What I am trying to do is that by using regular expressions how I can check if the number is correct for each country individually. I do not know how I have to merge countrycode and phone number from entered value by user and then check it all together. Lets say if it is for United States it has to validate number by US number, if it is for Switzerland it has to check it for Switzerland. I am able to add general regular expression by using pattern:// but I do not know how I can do it for each country separately. in the given code it only tests input with country code but it should not do it because country code has to be taken into consideration from CountryCodeSelector and then regex has to check it. I know this problem is not that much easy but can someone help me to solve it ? Thanks in advance

<div className={classes.phoneInputs} id="phone">
        <FormControl className={classes.phoneSuffix}>
          <Controller
            name="phoneSuffix"
            control={control}
            render={({ onChange, value }) => (
              <CountryCodeSelector value={value} onChange={onChange} />
            )}
          />
         
        </FormControl>
        <Input
          inputRef={register({
            required:true,
             pattern:/^\+(?:[0-9] ?){6,12}[0-9]$/im

           })}
        
          
          name="phone"
          placeholder="XXX XXX XXX"
          className={classes.phoneInput}
          error={!!errors?.phone}
          onBlur={handleBlurPhone}
          data-test="form-phone"
        />
      </div>

I am adding some photos here to express the issue much more detailed: [without anything][1]

it has to only consist of numbers not any sign because country code has to be checked by regex but I do not know how I can do it for each countries seperately

[regex has to take into consideration that country code is there already and it should not work and has to give error but it is not giving error][3]

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda