Validation process

download Validation process

of 2

description

Validation process

Transcript of Validation process

  • ///VALIDATE IN SAVE BUTTON (pROCESS)

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) { boolean isvalidated=false; String FIRST_NAME=txtFirstname.getText(); String LAST_NAME=txtLastname.getText(); String ADDRESS= txtAddress.getText(); String PHONE_NUM= txtContact.getText(); String EMAIL = txtEmail.getText(); if(Validate.checklength(FIRST_NAME,"First name")==false || Validate.isString(FIRST_NAME, "First name")==false){ txtFirstname.requestFocus(); isvalidated = false; return; }else{ isvalidated = true; } if(Validate.checklength(LAST_NAME,"Last name")==false || Validate.isString(LAST_NAME, "Last name")==false){ txtLastname.requestFocus(); isvalidated = false; return; }else{ isvalidated = true; } if(Validate.checklength(ADDRESS,"Address")==false || Validate.isString(ADDRESS, "Address")==false){ txtAddress.requestFocus(); isvalidated = false; return; }else{ isvalidated = true; } if(Validate.checklength(PHONE_NUM,"Contact Number")==false || Validate.isContact(PHONE_NUM, "Contact Number")==false){ txtContact.requestFocus(); isvalidated = false; return; }else{ isvalidated = true; } if(Validate.checklength(EMAIL,"Email")==false || Validate.isEmail(EMAIL, "Email")==false){ txtEmail.requestFocus(); isvalidated = false; return; }else{ isvalidated = true; }

  • //////////////////////////////////////////////////////VALIDATION CLASS

    public class Validate { public static boolean isEmail(String n ,String message){ if(n.matches("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$")){ return true; }else{ JOptionPane.showMessageDialog(null,"Please Enter Proper "+message); return false; } } public static boolean isString(String n ,String message){ if(n.matches("[a-zA-Z\\_ \\.]+$")){ return true; }else{ JOptionPane.showMessageDialog(null,"Please Enter Proper "+message); return false; } } public static boolean checklength(String n,String message){ if(n.length()>=0){ return true; }else{ JOptionPane.showMessageDialog(null,"Please Enter Proper "+message); return false; } } public static boolean isContact(String n ,String message){ if(n.matches("^[0-9]{10}$")){ return true; }else{ JOptionPane.showMessageDialog(null,"Please Enter Proper "+message); return false; } }}