Package com.controllers

Source Code of com.controllers.RegistrationValidation

package com.controllers;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import com.form.Registration;

@Component("registrationValidator")
public class RegistrationValidation {
  public boolean supports(Class<?> klass) {
    return Registration.class.isAssignableFrom(klass);
  }

  public void validate(Object target, Errors errors) {
    Registration registration = (Registration) target;
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userName",
        "NotEmpty.registration.userName",
        "User Name must not be Empty.");
    String userName = registration.getUserName();
    if ((userName.length()) > 50) {
      errors.rejectValue("userName",
          "lengthOfUser.registration.userName",
          "User Name must not more than 50 characters.");
    }
    if (!(registration.getPassword()).equals(registration
        .getConfirmPassword())) {
      errors.rejectValue("password",
          "matchingPassword.registration.password",
          "Password and Confirm Password Not match.");
    }
  }
}
TOP

Related Classes of com.controllers.RegistrationValidation

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.