List of usage examples for org.springframework.validation ValidationUtils rejectIfEmptyOrWhitespace
public static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode)
From source file:CRM.Validation.InteractionsValidation.java
@Override public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "first_name", "interactions.first_name.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "last_name", "interactions.last_name.required"); ValidationUtils.rejectIfEmpty(errors, "status", "interactions.status.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "method_of_contact", "interactions.method_of_contact.required"); // ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "interactions.email.required"); // ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone", "interactions.phone.required"); ValidationUtils.rejectIfEmpty(errors, "notes", "interactions.notes.required"); interactions interactions = (interactions) target; if (interactions.getFirst_name().length() > 45) { errors.rejectValue("first_name", "interactions.first_name.length"); }/*w w w . ja v a 2 s . c om*/ if (interactions.getLast_name().length() > 45) { errors.rejectValue("last_name", "interactions.last_name.length"); } if (interactions.getStatus().length() > 45) { errors.rejectValue("status", "interactions.status.length"); } if (interactions.getMethod_of_contact().length() > 45) { errors.rejectValue("method_of_contact", "interactions.method_of_contact.length"); } // if(interactions.getEmail().length() > 64) { // errors.rejectValue("email", "interactions.email.length"); // } // if(interactions.getPhone().length() > 16) { // errors.rejectValue("phone", "interactions.phone.length"); // } if (interactions.getFirst_name() != null && !interactions.getFirst_name().matches("^[A-Za-z]{2,45}$")) { errors.rejectValue("first_name", "interactions.first_name.pattern"); } if (interactions.getLast_name() != null && !interactions.getLast_name().matches("^[A-Za-z]{2,45}$")) { errors.rejectValue("last_name", "interactions.last_name.pattern"); } // if(interactions.getEmail() != null && !interactions.getEmail().matches("^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$")) { // errors.rejectValue("email", "interactions.email.pattern"); // } // if(interactions.getPhone() != null && !interactions.getPhone().matches("(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])?$")) { // errors.rejectValue("phone", "interactions.phone.pattern"); // } }
From source file:org.openmrs.module.restrictbyrole.RoleRestrictionValidator.java
public void validate(Object o, Errors errors) { RoleRestriction rr = (RoleRestriction) o; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "role", "error.role"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "searchId", "error.search"); }
From source file:org.openmrs.module.restrictbyuser.UserRestrictionValidator.java
public void validate(Object o, Errors errors) { UserRestriction rr = (UserRestriction) o; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "user", "error.user"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "searchId", "error.search"); }
From source file:com.web.mavenproject6.validators.UsersValidator.java
@Override public void validate(Object obj, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "messages.users.email"); // Users emp = (Users) obj; // if(emp.getId() <=0){ // errors.rejectValue("id", "negativeValue", new Object[]{"'id'"}, "id can't be negative"); // }/*from w w w .j a va 2s . c om*/ // // ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "name.required"); // ValidationUtils.rejectIfEmptyOrWhitespace(errors, "role", "role.required"); }
From source file:CRM.Validation.ClientsValidation.java
@Override public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "first_name", "clients.first_name.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "last_name", "clients.last_name.required"); ValidationUtils.rejectIfEmpty(errors, "address_1", "clients.address_1.required"); ValidationUtils.rejectIfEmpty(errors, "city", "clients.city.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "zip", "clients.zip.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone", "clients.phone.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "clients.email.required"); ValidationUtils.rejectIfEmpty(errors, "date_of_hire", "clients.date_of_hire"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "file_number", "clients.file_number.required"); ValidationUtils.rejectIfEmpty(errors, "status", "clients.status.required"); clients clients = (clients) target;/* ww w .j ava 2 s. c o m*/ if (clients.getFirst_name().length() > 45) { errors.rejectValue("first_name", "clients.first_name.length"); } if (clients.getLast_name().length() > 45) { errors.rejectValue("last_name", "clients.last_name.length"); } if (clients.getAddress_1().length() > 128) { errors.rejectValue("address_1", "clients.address_1.length"); } if (clients.getAddress_2().length() > 128) { errors.rejectValue("address_2", "clients.address_2.length"); } if (clients.getAddress_3().length() > 128) { errors.rejectValue("address_3", "clients.address_3.length"); } if (clients.getCity().length() > 64) { errors.rejectValue("city", "clients.city.length"); } if (clients.getZip().length() > 16) { errors.rejectValue("zip", "clients.zip.length"); } if (clients.getPhone().length() > 16) { errors.rejectValue("phone", "clients.phone.length"); } if (clients.getFax().length() > 16) { errors.rejectValue("fax", "clients.fax.length"); } if (clients.getEmail().length() > 45) { errors.rejectValue("email", "clients.email.length"); } if (clients.getDate_of_hire().length() > 45) { errors.rejectValue("date_of_hire", "clients.date_of_hire.length"); } if (clients.getFile_number().length() > 45) { errors.rejectValue("file_number", "clients.file_number.length"); } if (clients.getStatus().length() > 45) { errors.rejectValue("status", "clients.status.length"); } if (clients.getFirst_name().matches("^[A-Za-z]{2,45}$/")) { errors.rejectValue("first_name", "clients.first_name.pattern"); } if (clients.getLast_name().matches("[^A-Za-z0-9_'-]{2,45}$/")) { errors.rejectValue("last_name", "clients.last_name.pattern"); } if (!clients.getAddress_1().matches( "\\d+[ ](?:[A-Za-z0-9.-]+[ ]?)+(?:Avenue|Lane|Road|Boulevard|Drive|Street|Ave|Dr|Rd|Blvd|Ln|St)\\.?")) { errors.rejectValue("address_1", "clients.address_1.pattern"); } if (!clients.getCity().matches("(?:[A-Z][a-z.-]+[ ]?)+")) { errors.rejectValue("city", "clients.city.pattern"); } if (clients.getZip() != null && !clients.getZip().matches("^\\b\\d{5}(?:-\\d{4})?\\b$")) { errors.rejectValue("zip", "clients.zip.pattern"); } if (!clients.getPhone().matches( "^(?:(?:\\+?1\\s*(?:[.-]\\s*)?)?(?:\\(\\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\\s*\\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\\s*(?:[.-]\\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\\s*(?:[.-]\\s*)?([0-9]{4})(?:\\s*(?:#|x\\.?|ext\\.?|extension)\\s*(\\d+))?$")) { errors.rejectValue("phone", "clients.phone.pattern"); } if (clients.getFax() != null && !clients.getFax().matches( "^(?:(?:\\+?1\\s*(?:[.-]\\s*)?)?(?:\\(\\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\\s*\\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\\s*(?:[.-]\\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\\s*(?:[.-]\\s*)?([0-9]{4})(?:\\s*(?:#|x\\.?|ext\\.?|extension)\\s*(\\d+))?$")) { errors.rejectValue("fax", "clients.fax.pattern"); } if (!clients.getEmail().matches( "^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$")) { errors.rejectValue("email", "clients.email.pattern"); } // if (!clients.getDate_of_hire().matches("(^(((0[1-9]|1[0-9]|2[0-8])[\\/](0[1-9]|1[012]))|((29|30|31)[\\/](0[13578]|1[02]))|((29|30)[\\/](0[4,6,9]|11)))[\\/](19|[2-9][0-9])\\d\\d$)|(^29[\\/]02[\\/](19|[2-9][0-9])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)$)")) { // errors.rejectValue("date_of_hire", "clients.date_of_hire.pattern"); // } }
From source file:alfio.util.Validator.java
public static ValidationResult validateEventHeader(Optional<Event> event, EventModification ev, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shortName", "error.shortname"); if (ev.getOrganizationId() < 0) { errors.rejectValue("organizationId", "error.organizationId"); }//from w w w . ja v a 2 s. c om ValidationUtils.rejectIfEmptyOrWhitespace(errors, "location", "error.location"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "websiteUrl", "error.websiteurl"); if (isInternal(event, ev)) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "error.description"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "termsAndConditionsUrl", "error.termsandconditionsurl"); } else { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "externalUrl", "error.externalurl"); } if (ev.getFileBlobId() == null) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "imageUrl", "error.imageurl"); if (!StringUtils.startsWith(ev.getImageUrl(), "https://")) { errors.rejectValue("imageUrl", "error.imageurl"); } } return evaluateValidationResult(errors); }
From source file:org.openmrs.web.form.visit.ConfigureVisitsFormValidator.java
@Override public void validate(Object target, Errors errors) { ConfigureVisitsForm form = (ConfigureVisitsForm) target; if (form.isEnableVisits()) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "visitEncounterHandler", "Encounter.error.visits.handler.empty"); }//www . ja va 2 s. co m }
From source file:validation.ClientsValidator.java
@Override public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstname", "Clients.firstname.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastname", "Clients.lastname.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "company", "Clients.company.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address1", "Clients.address1.required"); //ValidationUtils.rejectIfEmptyOrWhitespace(errors,"address2", "Clients.address2.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "city", "Clients.city.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "state", "Clients.state.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "zip", "Clients.zip.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone", "Clients.phone.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "Clients.email.required"); Clients clients = (Clients) target;/*from w w w . ja v a 2 s .co m*/ if (clients.getFirstname().length() > 120) { errors.rejectValue("firstname", "clients.firstname.length"); } if (clients.getLastname().length() > 120) { errors.rejectValue("lastname", "clients.lastname.length"); } if (clients.getAddress1().length() > 120) { errors.rejectValue("address1", "clients.address1.length"); } if (clients.getAddress2().length() > 120) { errors.rejectValue("address2", "clients.address2.length"); } if (clients.getCity().length() > 120) { errors.rejectValue("city", "clients.city.length"); } if (clients.getState().length() > 120) { errors.rejectValue("state", "clients.state.length"); } if (clients.getZip().length() > 20) { errors.rejectValue("zip", "clients.zip.length"); } if (clients.getPhone().length() > 20) { errors.rejectValue("phone", "clients.phone.length"); } if (clients.getEmail().length() > 120) { errors.rejectValue("email", "clients.email.length"); } if (!clients.getFirstname().matches("^[A-Za-z0-9]*$")) { errors.rejectValue("firstname", "clients.firstname.pattern"); } if (!clients.getLastname().matches("^[A-Za-z0-9]*$")) { errors.rejectValue("lastname", "clients.lastname.pattern"); } if (!clients.getCity().matches("^[A-Za-z0-9]*$")) { errors.rejectValue("city", "clients.city.pattern"); } if (!clients.getEmail().matches( "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")) { errors.rejectValue("email", "clients.email.pattern"); } }
From source file:org.openmrs.module.spreadsheetimport.validators.SpreadsheetImportTemplateValidator.java
public void validate(Object obj, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", ""); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", ""); SpreadsheetImportTemplate template = (SpreadsheetImportTemplate) obj; for (int i = 0; i < template.getColumns().size(); i++) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "columns[" + i + "].name", ""); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "columns[" + i + "].tableDotColumn", ""); }/*from w ww . j a v a 2s. c o m*/ // for (int i = 0; i < template.getPrespecifiedValues().size(); i++) { // ValidationUtils.rejectIfEmptyOrWhitespace(errors, "prespecifiedValues["+i+"].value", ""); // } }
From source file:mylife.validator.interactionsValidator.java
/** * * @param target/* w ww . j a v a2 s .co m*/ * @param errors */ @Override public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "clientsid", "interactions.clientsid.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "date_of_contact", "interactions.date_of_contact.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "contact_name", "interactions.contact_name.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "contact_type", "interactions.contact_type.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "conversation", "interactions.conversation.required"); interactions interactions = (interactions) target; if (interactions.getDate_of_contact().length() > 120) { errors.rejectValue("date_of_contact", "interactions.date_of_contact.length"); } if (!interactions.getDate_of_contact().matches("^[A-Za-z0-9]*$")) { errors.rejectValue("date_of_contact", "interactions.date_of_contact.pattern"); } if (interactions.getContact_name().length() > 120) { errors.rejectValue("contact_name", "interactions.contact_name.length"); } if (interactions.getContact_name().matches("^[A-Za-z0-9]*$")) { errors.rejectValue("contact_name", "interactions.contact_name.pattern"); } if (interactions.getContact_type().length() > 45) { errors.rejectValue("contact_type", "interactions.contact_type.length"); } if (!interactions.getContact_type().matches("^[A-Za-z0-9]*$")) { errors.rejectValue("contact_type", "interactions.contact_type.pattern"); } if (interactions.getConversation().length() > 200) { errors.rejectValue("conversation", "interactions.conversation.length"); } if (!interactions.getConversation().matches("^[A-Za-z0-9]*$")) { errors.rejectValue("conversation", "interaction.conversation.pattern"); } }