private void btnPCreateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPCreateActionPerformed
        // TODO add your handling code here:
        lblPHint.setVisible(false);
        if(tbxPDoctorID.getText().equals(""))
        {
            tbxError.setText("Permission denied.");
            return ;
        }
        Pattern namepattern = Pattern.compile("^[A-Z][a-zA-Z ,.'-]*$");
        String fn = tbxPFirstName.getText().trim();
        if (!namepattern.matcher(fn).matches())
        {
            tbxError.setText("Invalid first name.");
            lblPHint.setText("Unacceptable first name.");
            lblPHint.setVisible(true);
            return ;
        }
        fn = fn.replace("'", "\\'");
        String ln = tbxPLastName.getText().trim();
        if (!namepattern.matcher(ln).matches())
        {
            tbxError.setText("Invalid last name.");
            lblPHint.setText("Unacceptable last name.");
            lblPHint.setVisible(true);
            return ;
        }
        ln = ln.replace("'", "\\'"); 
        Pattern pattern = Pattern.compile("[0-9]{4}/[0-9]{2}/[0-9]{2}");
        Pattern pattern2 = Pattern.compile("[0-9]{2}/[0-9]{2}/[0-9]{4}");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        Date bd = new Date();
        String tbd = tbxPBirthDate.getText();
        if (pattern.matcher(tbd).matches())
        {
            //bd = sdf.parse(tbxBirthDate.getText());
            sdf = new SimpleDateFormat("yyyy/MM/dd");
        }
        else if (pattern2.matcher(tbd).matches())
        {
            sdf = new SimpleDateFormat("MM/dd/yyyy");
        }
        else
        {
            tbxError.setText("Invalid birthdate.");
            lblPHint.setText("Wrong Format. Example: "+"2000/01/01");
            lblPHint.setVisible(true);
            return ;
        }
        try
        {
            bd = sdf.parse(tbxPBirthDate.getText());
        }
        catch(Exception e)
        {
            tbxError.setText("Invalid birthdate.");
            lblPHint.setText("Wrong Format. Example: "+"2000/01/01");
            lblPHint.setVisible(true);
            return ;
        }
        String Address = tbxPAddress1.getText().replace("'", "\\'").replace(";", "");
        Address +=";";
        Address += tbxPAddress2.getText().replace("'", "\\'").replace(";", "");
        if (Address.equals(";"))
        {
            tbxError.setText("Empty address.");
            return ;
        }
        pattern = Pattern.compile("[0-9]{5}");
        
        String zc = tbxPZipcode.getText().trim().replace("'", "");
        if (!pattern.matcher(zc).matches())
        {
            tbxError.setText("Invalid zipcode.");
            lblPHint.setText("Wrong Format. Example: "+"25858");
            lblPHint.setVisible(true);
            return ;
        }
        
        String ph = tbxPPhone.getText().trim().replace("'", "");
        pattern = Pattern.compile("[0-9]{3}\\-?[0-9]{3}\\-?[0-9]{4}");
        if (!pattern.matcher(ph).matches())
        {
            tbxError.setText("Invalid phone number.");
            lblPHint.setText("Wrong Format. Example: "+"919-360-5662");
            lblPHint.setVisible(true);
            return ;
        }
        ph = ph.replace("-", "");
        ph = ph.substring(0,3)+"-"+ph.substring(3,6)+"-"+ph.substring(6);
        Patient_Controller PC = new Patient_Controller("localhost", DBName, DBAccount, DBPwd);
        
        int id = PC.CreatePatient(fn, ln, (cbxPGender.getSelectedIndex()==0), bd, Address, zc, ph, ThisUser.UserID);
        if(id<=0)
        {
            tbxError.setText(PC.err);
            return;
        }
        ReturnedPatients = PC.SearchPatient(id);
        ShowPatients();
        tbxError.setText("Patient #" + id +" is added successfully.");
    }