Example usage for com.liferay.portal.kernel.util Validator isPhoneNumber

List of usage examples for com.liferay.portal.kernel.util Validator isPhoneNumber

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util Validator isPhoneNumber.

Prototype

public static boolean isPhoneNumber(String phoneNumber) 

Source Link

Document

Returns true if the string is a valid phone number.

Usage

From source file:com.inkwell.internet.productregistration.portlet.ProdRegValidator.java

License:Open Source License

/**
 * Validates a RegUser object.//from www .j  a  va  2s . com
 *
 * @param user
 * @param errors
 * @return boolean
 */
public static boolean validateUser(PRUser user, List errors) {
    boolean valid = true;

    if (Validator.isNull(user.getFirstName())) {
        errors.add("firstname-required");
        valid = false;
    }

    if (Validator.isNull(user.getLastName())) {
        errors.add("lastname-required");
        valid = false;
    }

    if (Validator.isNull(user.getAddress1()) || Validator.isNull(user.getCity())
            || Validator.isNull(user.getState()) || Validator.isNull(user.getPostalCode())
            || Validator.isNull(user.getCountry())) {

        errors.add("address-required");
        valid = false;
    }

    if (Validator.isNull(user.getEmail())) {
        errors.add("email-required");
        valid = false;
    }

    if (Validator.isNull(user.getPhoneNumber())) {
        errors.add("phone-number-required");
        valid = false;
    } else {

        if (!Validator.isPhoneNumber(user.getPhoneNumber())) {
            errors.add("phone-number-required");
            valid = false;
        }

    }

    if (Validator.isNotNull(user.getBirthDate())) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(user.getBirthDate());
        if (!Validator.isDate(calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH),
                calendar.get(Calendar.YEAR))) {
            errors.add("enter-valid-date");
            valid = false;
        }
    } else {
        errors.add("birthdate-required");
        valid = false;
    }

    if (Validator.isNull(user.getGender())) {
        errors.add("gender-required");
        valid = false;
    }

    if (Validator.isNull(user.getCompanyId())) {
        errors.add("missing-company-id");
        valid = false;
    }

    if (Validator.isNull(user.getGroupId())) {
        errors.add("missing-group-id");
        valid = false;
    }

    return valid;

}

From source file:com.inkwell.internet.productregistration.registration.portlet.ProdRegValidator.java

License:Open Source License

/**
 * Validates a RegUser object.//from   ww w  . jav a  2s  .com
 *
 * @param user
 * @param errors
 * @return boolean
 */
public static boolean validateUser(PRUser user, List errors) {

    boolean valid = true;

    if (Validator.isNull(user.getFirstName())) {
        errors.add("firstname-required");
        valid = false;
    }

    if (Validator.isNull(user.getLastName())) {
        errors.add("lastname-required");
        valid = false;
    }

    if (Validator.isNull(user.getAddress1()) || Validator.isNull(user.getCity())
            || Validator.isNull(user.getState()) || Validator.isNull(user.getPostalCode())
            || Validator.isNull(user.getCountry())) {

        errors.add("address-required");
        valid = false;
    }

    if (Validator.isNull(user.getEmail())) {
        errors.add("email-required");
        valid = false;
    }

    if (Validator.isNull(user.getPhoneNumber())) {
        errors.add("phone-number-required");
        valid = false;
    } else {

        if (!Validator.isPhoneNumber(user.getPhoneNumber())) {
            errors.add("phone-number-required");
            valid = false;
        }

    }

    if (Validator.isNotNull(user.getBirthDate())) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(user.getBirthDate());
        if (!Validator.isDate(calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH),
                calendar.get(Calendar.YEAR))) {
            errors.add("enter-valid-date");
            valid = false;
        }
    } else {
        errors.add("birthdate-required");
        valid = false;
    }

    if (Validator.isNull(user.getGender())) {
        errors.add("gender-required");
        valid = false;
    }

    if (Validator.isNull(user.getCompanyId())) {
        errors.add("missing-company-id");
        valid = false;
    }

    if (Validator.isNull(user.getGroupId())) {
        errors.add("missing-group-id");
        valid = false;
    }

    return valid;

}

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  w  ww  .  j a  va2  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.faces.demos.service.RegistrantServiceUtil.java

License:Open Source License

private static void updateMobilePhone(long creatorUserId, long companyId, Registrant registrant)
        throws SystemException, PortalException {
    List<Phone> phones = new ArrayList<Phone>();
    String mobilePhone = registrant.getMobilePhone();

    if (Validator.isNotNull(mobilePhone)) {

        if (Validator.isPhoneNumber(mobilePhone)) {
            Phone phone = PhoneUtil.create(0L);
            phone.setUserId(registrant.getUserId());
            phone.setCompanyId(companyId);
            phone.setNumber(mobilePhone);
            phone.setPrimary(true);/*ww  w  .  ja va  2 s.c o m*/
            phone.setTypeId(getMobilePhoneTypeId());
            phones.add(phone);

            PermissionChecker permissionCheckerBackup = PermissionThreadLocal.getPermissionChecker();
            PermissionThreadLocal.setPermissionChecker(getAdministratorPermissionChecker(companyId));

            // Note: Exception will be thrown if we don't set the PrinicpalThreadLocal name.
            String principalNameBackup = PrincipalThreadLocal.getName();
            PrincipalThreadLocal.setName(creatorUserId);
            UsersAdminUtil.updatePhones(Contact.class.getName(), registrant.getContactId(), phones);
            PrincipalThreadLocal.setName(principalNameBackup);
            PermissionThreadLocal.setPermissionChecker(permissionCheckerBackup);
        } else {

            if (!"N/A".equalsIgnoreCase(mobilePhone)) {
                logger.error("Invalid mobilePhone=[{0}] for registrant=[{1}]", mobilePhone,
                        registrant.getFullName());
            }
        }
    }
}

From source file:com.liferay.jbpm.WorkflowComponentImpl.java

License:Open Source License

protected String validate(TaskFormElement taskFormElement, Map parameterMap) {

    String error = null;/*from  w w  w .  j  a  va  2s . c  o m*/

    String type = taskFormElement.getType();
    String name = taskFormElement.getDisplayName();
    String value = getParamValue(parameterMap, name);

    if (type.equals(TaskFormElement.TYPE_CHECKBOX)) {
        if (taskFormElement.isRequired() && value.equals("false")) {
            error = "required-value";
        }
    } else if (type.equals(TaskFormElement.TYPE_DATE)) {
        value = getParamValue(parameterMap, JS.getSafeName(name));

        if (taskFormElement.isRequired()) {
            try {
                formatDate(value);

                String[] dateValues = StringUtil.split(value, "/");

                int month = GetterUtil.getInteger(dateValues[0]) - 1;
                int day = GetterUtil.getInteger(dateValues[1]);
                int year = GetterUtil.getInteger(dateValues[2]);

                if (!Validator.isDate(month, day, year)) {
                    error = "invalid-date";
                }
            } catch (Exception e) {
                error = "invalid-date";
            }
        }
    } else if (type.equals(TaskFormElement.TYPE_EMAIL)) {
        if (taskFormElement.isRequired() && Validator.isNull(value)) {
            error = "required-value";
        } else if (!Validator.isNull(value) && !Validator.isEmailAddress(value)) {

            error = "invalid-email";
        }
    } else if (type.equals(TaskFormElement.TYPE_NUMBER)) {
        if (taskFormElement.isRequired() && Validator.isNull(value)) {
            error = "required-value";
        } else if (!Validator.isNull(value) && !Validator.isNumber(value)) {
            error = "invalid-number";
        }
    } else if (type.equals(TaskFormElement.TYPE_PASSWORD)) {
        if (taskFormElement.isRequired() && Validator.isNull(value)) {
            error = "required-value";
        }
    } else if (type.equals(TaskFormElement.TYPE_PHONE)) {
        if (taskFormElement.isRequired() && Validator.isNull(value)) {
            error = "required-value";
        } else if (!Validator.isNull(value) && !Validator.isPhoneNumber(value)) {

            error = "invalid-phone";
        }
    } else if (type.equals(TaskFormElement.TYPE_RADIO)) {
        if (taskFormElement.isRequired() && Validator.isNull(value)) {
            error = "required-value";
        }
    } else if (type.equals(TaskFormElement.TYPE_SELECT)) {
        if (taskFormElement.isRequired() && Validator.isNull(value)) {
            error = "required-value";
        }
    } else if (type.equals(TaskFormElement.TYPE_TEXT)) {
        if (taskFormElement.isRequired() && Validator.isNull(value)) {
            error = "required-value";
        }
    } else if (type.equals(TaskFormElement.TYPE_TEXTAREA)) {
        if (taskFormElement.isRequired() && Validator.isNull(value)) {
            error = "required-value";
        }
    }

    return error;
}

From source file:com.liferay.portlet.login.action.CreateAccountAction.java

License:Open Source License

protected void addUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
    HttpSession session = request.getSession();

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Company company = themeDisplay.getCompany();

    boolean autoPassword = true;
    String password1 = null;//from w w w .j  a v a  2  s . c  om
    String password2 = null;
    boolean autoScreenName = isAutoScreenName();
    String screenName = ParamUtil.getString(actionRequest, "screenName");
    String emailAddress = ParamUtil.getString(actionRequest, "emailAddress");
    long facebookId = ParamUtil.getLong(actionRequest, "facebookId");
    String openId = ParamUtil.getString(actionRequest, "openId");
    String firstName = ParamUtil.getString(actionRequest, "firstName");
    String middleName = ParamUtil.getString(actionRequest, "middleName");
    String lastName = ParamUtil.getString(actionRequest, "lastName");
    int prefixId = ParamUtil.getInteger(actionRequest, "prefixId");
    int suffixId = ParamUtil.getInteger(actionRequest, "suffixId");
    boolean male = ParamUtil.getBoolean(actionRequest, "male", true);
    int birthdayMonth = ParamUtil.getInteger(actionRequest, "birthdayMonth");
    int birthdayDay = ParamUtil.getInteger(actionRequest, "birthdayDay");
    int birthdayYear = ParamUtil.getInteger(actionRequest, "birthdayYear");
    String jobTitle = ParamUtil.getString(actionRequest, "jobTitle");
    long[] groupIds = null;
    long[] organizationIds = null;
    long[] roleIds = null;
    long[] userGroupIds = null;
    boolean sendEmail = true;

    ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest);

    if (PropsValues.LOGIN_CREATE_ACCOUNT_ALLOW_CUSTOM_PASSWORD) {
        autoPassword = false;

        password1 = ParamUtil.getString(actionRequest, "password1");
        password2 = ParamUtil.getString(actionRequest, "password2");
    }

    boolean openIdPending = false;

    Boolean openIdLoginPending = (Boolean) session.getAttribute(WebKeys.OPEN_ID_LOGIN_PENDING);

    if ((openIdLoginPending != null) && (openIdLoginPending.booleanValue()) && (Validator.isNotNull(openId))) {

        sendEmail = false;
        openIdPending = true;
    }

    // check accountRole - numberPhone
    String accountRole = ParamUtil.getString(actionRequest, "accountRole", "");
    String mobilePhone = ParamUtil.getString(actionRequest, "mobilePhone", "");
    boolean subscriberAccount = false;

    if (accountRole.equals("subscriberAccount")) {
        subscriberAccount = true;
        if (!Validator.isPhoneNumber(mobilePhone)) {
            throw new Exception("mobile-phone-invalid");
        }

        try {
            UserEntry tmpEmtry = UserEntryLocalServiceUtil.findByMobilePhone(mobilePhone);
            if (tmpEmtry != null)
                throw new Exception("mobile-phone-invalid");
        } catch (Exception e) {
            // TODO: handle exception

        }

    }
    //accountRole
    User user = UserServiceUtil.addUserWithWorkflow(company.getCompanyId(), autoPassword, password1, password2,
            autoScreenName, screenName, emailAddress, facebookId, openId, themeDisplay.getLocale(), firstName,
            middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle,
            groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);

    if (openIdPending) {
        session.setAttribute(WebKeys.OPEN_ID_LOGIN, new Long(user.getUserId()));
        session.removeAttribute(WebKeys.OPEN_ID_LOGIN_PENDING);
    } else {

        // Session messages

        if (user.getStatus() == WorkflowConstants.STATUS_APPROVED) {
            SessionMessages.add(request, "user_added", user.getEmailAddress());
            SessionMessages.add(request, "user_added_password", user.getPasswordUnencrypted());
        } else {
            SessionMessages.add(request, "user_pending", user.getEmailAddress());
        }
    }

    // ============================================================
    // create user success - ok then create vrbt_user
    // add new UserEntry ( vrbt_user table ) 
    UserEntry userEntry = null;
    try {
        userEntry = UserEntryLocalServiceUtil
                .createUserEntry(CounterLocalServiceUtil.increment(UserEntry.class.getName()));
        userEntry.setUserId(user.getUserId());
        userEntry.setUserName(user.getScreenName());
        userEntry.setGroupId(user.getGroupId());
        userEntry.setCompanyId(user.getCompanyId());
        userEntry.setCreateDate(Calendar.getInstance().getTime());
        userEntry.setStatus(1);
        if (subscriberAccount) {
            userEntry.setMobilePhone(mobilePhone);
        }
        UserEntryLocalServiceUtil.updateUserEntry(userEntry);
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }

    // add role
    long roleId = 0;
    try {
        Role role = null;
        if (subscriberAccount) {
            role = RoleLocalServiceUtil.getRole(PortalUtil.getCompanyId(request), "Subscriber");
            if (role != null)
                roleId = role.getRoleId();
        } else {
            role = RoleLocalServiceUtil.getRole(PortalUtil.getCompanyId(request), "Third-party");
            if (role != null)
                roleId = role.getRoleId();
        }
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
    System.out.println("roleId:" + roleId);
    if (roleId > 0) {
        try {
            RoleLocalServiceUtil.addUserRoles(user.getUserId(), new long[] { roleId });

        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    }
    // ============================================================
    // Send redirect

    String login = null;

    if (company.getAuthType().equals(CompanyConstants.AUTH_TYPE_ID)) {
        login = String.valueOf(user.getUserId());
    } else if (company.getAuthType().equals(CompanyConstants.AUTH_TYPE_SN)) {
        login = user.getScreenName();
    } else {
        login = user.getEmailAddress();
    }
    // fix 
    login = user.getScreenName();
    // 
    sendRedirect(actionRequest, actionResponse, themeDisplay, login, user.getPasswordUnencrypted());
}

From source file:com.rivetlogic.event.util.EventValidator.java

License:Open Source License

public static boolean validateParticipantInfo(Participant participant, List<Participant> participants,
        List<String> errors, List<String> repeatedEmails, List<String> invalidEmails) {

    boolean isValid = false;

    if (Validator.isNull(participant.getFullName())) {
        errors.add(PARTICIPANT_FULL_NAME_REQUIRED);
    }//  w w  w . j a  va2 s .  c  o m

    if (Validator.isNull(participant.getPhoneNumber())) {
        errors.add(PARTICIPANT_PHONE_REQUIRED);

    } else if (!Validator.isPhoneNumber(participant.getPhoneNumber())) {
        errors.add(PARTICIPANT_PHONE_INVALID);
    }

    if (Validator.isNull(participant.getCompanyName())) {
        errors.add(PARTICIPANT_COMPANY_NAME_REQUIRED);
    }

    String participantEmail = participant.getEmail();

    if (Validator.isNull(participantEmail)) {
        errors.add(PARTICIPANT_EMAIL_REQUIRED);

    } else if (!Validator.isEmailAddress(participantEmail)) {
        errors.add(PARTICIPANT_INVALID_EMAIL + participantEmail);

        if (!invalidEmails.contains(participantEmail)) {
            invalidEmails.add(participantEmail);
        }

    } else {

        if (Validator.isNotNull(participants)) {

            for (int i = 0; i < participants.size(); ++i) {

                if (participants.get(i).getEmail().equals(participantEmail)) {
                    errors.add(PARTICIPANT_REPEATED_EMAIL + participantEmail);
                    if (!repeatedEmails.contains(participantEmail)) {
                        repeatedEmails.add(participantEmail);
                    }
                }
            }

        }
    }

    if (errors.isEmpty()) {
        isValid = true;
    }

    return isValid;
}