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

349
Visualizações
Ant Design, React, TypeScript - Form regex pattern validation stopped working after adding custom validator

I have 2 phone number fields in my form. Previously I had only 'required' and regex pattern validations but I added a custom validator so I can check if the 2 fields are equal to each other. When I added the custom validator, the regex pattern stopped working. Any thoughts?

 <Form.Item
            name="primary_phone_number"
            className={styles.formItem}
            label={<span className={styles.label}>PRIMARY PHONE NUMBER*</span>}
            colon={false}
            rules={[
              {
                required: true,
                message: 'The field cannot be empty',
              },
              {
                pattern: /^[+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,6}$/im,
                message: 'Please, enter a valid phone number',
              },
              {
                validator: (_, value, callback) => {
                  const secondaryNumber = formRef.current.getFieldValue('secondary_phone_number');

                  if (value === secondaryNumber)
                    callback('Primary and Secondary phone numbers must be different.');
                },
              },
            ]}
          >
            <Input
              defaultValue={user?.primary_phone_number?.value}
              placeholder="Primary Phone Number"
              className={combineCss(
                styles.input,
                userFields?.primary_phone_number?.length ? styles.filled : '',
              )}
              onChange={(e: any) => onChangeSelectOptions('primary_phone_number', e.target.value)}
            />
      </Form.Item>

The second field is similar to this one with the same validations.

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