List of usage examples for com.liferay.portal.kernel.util CalendarUtil getAge
public static int getAge(Date date, TimeZone tz)
From source file:com.amf.registration.portlet.RegistrationPortlet.java
License:Open Source License
protected void validate(String firstName, String lastName, String emailAddress, String username, int birthdayMonth, int birthdayDay, int birthdayYear, String password1, String password2, String homePhone, String mobilePhone, String address, String address2, String city, String zip, String securityQuestion, String securityAnswer, boolean acceptedTou) throws Exception { if (!Validator.isAlphanumericName(firstName) || (firstName.length() > 50)) { throw new ContactFirstNameException(); }//from w w w. j a va 2s .c o m if (!Validator.isAlphanumericName(lastName) || (lastName.length() > 50)) { throw new ContactLastNameException(); } if (Validator.isNull(emailAddress) || (emailAddress.length() > 75)) { throw new UserEmailAddressException(); } if ((username.length() < 4) || (username.length() > 16) || !Validator.isAlphanumericName(username)) { throw new UserScreenNameException(); } Date birthday = PortalUtil.getDate(birthdayMonth, birthdayDay, birthdayYear, ContactBirthdayException.class); Date now = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(now); int age = CalendarUtil.getAge(birthday, calendar); if (age < 13) { throw new ContactBirthdayException(); } validatePassword(password1, password2); if (Validator.isNotNull(homePhone)) { if (!Validator.isDigit(homePhone) || (homePhone.length() != 10)) { throw new PhoneNumberException(); } } if (Validator.isNotNull(mobilePhone)) { if (!Validator.isDigit(mobilePhone) || (mobilePhone.length() != 10)) { throw new PhoneNumberException(); } } if (!Validator.isAlphanumericName(address) || (address.length() > 75)) { throw new AddressStreetException(); } if (Validator.isNotNull(address2) && (!Validator.isAlphanumericName(address2) || (address2.length() > 75))) { throw new AddressStreetException(); } if (!Validator.isAlphanumericName(city) || (city.length() > 75)) { throw new AddressCityException(); } if (!Validator.isDigit(zip) || (zip.length() != 5)) { throw new AddressZipException(); } if (Validator.isNull(securityQuestion) || Validator.isNull(securityAnswer) || !Validator.isAlphanumericName(securityAnswer) || (securityAnswer.length() > 75)) { throw new UserReminderQueryException(); } if (acceptedTou == false) { throw new TermsOfUseException(); } }
From source file:com.amf.registration.registration.portlet.AMFRegistrationPortlet.java
License:Open Source License
protected void validate(String firstName, String lastName, String emailAddress, String userName, int birthdayMonth, int birthdayDay, int birthdayYear, String password1, String homePhone, String mobilePhone, String address1, String address2, String city, String zip, String securityAnswer, boolean termsOfUse) throws PortalException { if (!Validator.isAlphanumericName(firstName) || (firstName.length() > 50)) { throw new ContactFirstNameException(); }//from w ww . j a va2 s. c om if (!Validator.isAlphanumericName(lastName) || (lastName.length() > 50)) { throw new ContactLastNameException(); } if (Validator.isNull(emailAddress) || (emailAddress.length() > 75)) { throw new UserEmailAddressException(); } if (!Validator.isAlphanumericName(userName) || ((userName.length() < 4) || (userName.length() > 16))) { throw new UserScreenNameException(); } Date birthday = PortalUtil.getDate(birthdayMonth, birthdayDay, birthdayYear, ContactBirthdayException.class); int age = CalendarUtil.getAge(birthday, CalendarFactoryUtil.getCalendar()); if (age < 13) { throw new ContactBirthdayException(); } validatePassword(password1); validateHomePhone(homePhone); validateMobilePhone(mobilePhone); validateAddress(address1, address2, city, zip); if (!Validator.isAlphanumericName(securityAnswer) || (securityAnswer.length() > 75)) { throw new UserReminderQueryException("answer-is-invalid"); } if (!termsOfUse) { throw new TermsOfUseException(); } }