-2
I’m doing a medical record for a hospital system test and I’d like to know how to validate the field CRM. It is a variable double, I want the field of Joptionpane accepted only numbers in CRM, I’ve tried several ways regular Expression etc and nothing worked out..
public static void cadastroMedico(){
int lista=1;
do{
acho=0;
codigoMedic=Integer.parseInt(JOptionPane.showInputDialog(null, "Digite o código do médico"));
if(medicos.size()>0)
for(int i = 0;i<medicos.size();i++){
if(codigoMedic==medicos.get(i).getIdMedico())
acho=1;
}
if(acho == 1)
JOptionPane.showMessageDialog(null, "Médico já cadastrado","Aviso",1);
}while(acho==1);
nomemed = JOptionPane.showInputDialog(null, "Digite o nome do Médico: ");
while(!matchesOnlyText(nomemed)) {
JOptionPane.showMessageDialog(null, "Você não pode inserir números no campo nome.");
nomemed = JOptionPane.showInputDialog(null, "Digite o nome do Médico: ");
}
**crm = Double.parseDouble(JOptionPane.showInputDialog(null, "Digite o CRM do Médico: "));**
setor = JOptionPane.showInputDialog(null, "Digite o setor do Médico: ");
while(!matchesOnlyText(setor)) {
JOptionPane.showMessageDialog(null, "Você não pode inserir números no campo setor.");
setor = JOptionPane.showInputDialog(null, "Digite o setor do Médico:");
}
}
When you say you want to validate CRM you mean format validation or validation of a doctor’s existence with this CRM number?
– MauroAlmeida
In the case I’m talking about format validation, but the most priority part in the case would be "I want the Joptionpane field to accept only CRM numbers".
– Felipebb
I am not finding the format of a CRM number, could indicate?
– MauroAlmeida
An example of CRM : 27134.
– Felipebb
because it needs to be double?
– MauroAlmeida
Regex to only be valid digits [0-9]+$
– MauroAlmeida
You’re right, I changed the CRM variable to Int, but it still doesn’t work.
– Felipebb