Jtextfield validation

Asked

Viewed 159 times

0

I’m trying to validate the field txtServicoValor who gets a guy BigDecimal, follows my code, the validation is barring both the correct form of the digits and the incorrect, I appreciate the help.

MaskFormatter mask = new MaskFormatter("###.###,#00.00");

JFormattedTextField campoTexto = new JFormattedTextField(mask);

mask.setValidCharacters("0123456789");

validos.install(campoTexto);

if(txtServico.getText().length() > 0
        && txtServicoValor.getText().length() > 0
        && (txtServicoValor.getText().replaceAll("\.", "").replace(",",".")).equals(campoTexto))
{
    servico.setServico(txtServico.getText());
    servico.setValorServico(new BigDecimal(txtServicoValor.getText().replaceAll("\.", "").replace(",",".")));
}
  • What becomes the variable validos?

  • there was a typo, what should be in place of valid would be the Mask object. Thanks for the help.

1 answer

1

Your problem is a very silly mistake. He’s here:

(txtServicoValor.getText().replaceAll("\.", "").replace(",",".")).equals(campoTexto)

This here is a String:

(txtServicoValor.getText().replaceAll("\.", "").replace(",","."))

This is from here JFormattedTextField:

campoTexto

One String will never be like a JFormattedTextField.

  • Thanks for the help! I will fix the code and test.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.