List of usage examples for com.liferay.portal.kernel.util Validator isAlphanumericName
public static boolean isAlphanumericName(String name)
true if the string is an alphanumeric name, meaning it contains nothing but English letters, numbers, and spaces. 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 av a2s.com*/ 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 w w. ja v a 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 (!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(); } }
From source file:com.amf.registration.registration.portlet.AMFRegistrationPortlet.java
License:Open Source License
protected void validateAddress(String address1, String address2, String city, String zip) throws PortalException { if (!Validator.isAlphanumericName(address1) || (address1.length() > 75)) { throw new AddressStreetException("address1-is-invalid"); }//from w ww .j a va 2 s . c o m if (Validator.isNotNull(address2)) { if (!Validator.isAlphanumericName(address2) || (address2.length() > 75)) { throw new AddressStreetException("address2-is-invalid"); } } if (!Validator.isAlphanumericName(city) || (city.length() > 75)) { throw new AddressCityException(); } if (!Validator.isDigit(zip) || (zip.length() != 5)) { throw new AddressZipException(); } }
From source file:com.liferay.adduser.service.impl.UserInfoLocalServiceImpl.java
License:Open Source License
protected void validate(String code, String username, String email, String phone) throws PortalException { if (Validator.isNull(code)) { throw new UserInfoCodeException(); }/*from ww w . j a v a 2 s . c o m*/ if (!Validator.isAlphanumericName(code)) { throw new UserInfoCodeException(); } if (Validator.isNull(username)) { throw new UserInfoUsernameException(); } if (!Validator.isEmailAddress(email)) { throw new UserInfoEmailException(); } if (!Validator.isPhoneNumber(phone)) { throw new UserInfoPhoneException(); } }
From source file:com.liferay.portlet.wiki.service.impl.WikiNodeLocalServiceImpl.java
License:Open Source License
protected void validate(long nodeId, long groupId, String name) throws PortalException, SystemException { if (name.equalsIgnoreCase("tag")) { throw new NodeNameException(name + " is reserved"); }//from w ww.j a v a 2 s. com if (!Validator.isAlphanumericName(name)) { throw new NodeNameException(); } WikiNode node = wikiNodePersistence.fetchByG_N(groupId, name); if ((node != null) && (node.getNodeId() != nodeId)) { throw new DuplicateNodeNameException(); } }
From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java
License:Open Source License
protected String stripRedundantParentheses(String s) { for (int x = 0;;) { x = s.indexOf(StringPool.OPEN_PARENTHESIS, x + 1); int y = s.indexOf(StringPool.CLOSE_PARENTHESIS, x); if ((x == -1) || (y == -1)) { return s; }//from ww w. j a v a 2s.c o m String linePart = s.substring(x + 1, y); linePart = StringUtil.replace(linePart, StringPool.COMMA, StringPool.BLANK); if (Validator.isAlphanumericName(linePart) || Validator.isNull(linePart)) { s = s.substring(0, x) + s.substring(y + 1); } } }