Example usage for org.apache.commons.lang StringUtils isAlphanumeric

List of usage examples for org.apache.commons.lang StringUtils isAlphanumeric

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils isAlphanumeric.

Prototype

public static boolean isAlphanumeric(String str) 

Source Link

Document

Checks if the String contains only unicode letters or digits.

Usage

From source file:org.telscenter.sail.webapp.presentation.validators.UserDetailsValidator.java

/**
 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
 *//*from w w w  .  j a  v a 2s .  c o  m*/
@Override
public void validate(Object userDetailsIn, Errors errors) {
    MutableUserDetails userDetails = (MutableUserDetails) userDetailsIn;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "error.password-not-specified");

    if (errors.getFieldErrorCount("password") > 0) {
        return;
    }

    if (userDetails.getPassword().length() > MAX_PASSWORD_LENGTH) {
        errors.rejectValue("password", "error.password-too-long");
        return;
    }

    if (!StringUtils.isAlphanumeric(userDetails.getPassword())) {
        errors.rejectValue("password", "error.password-illegal-characters");
        return;
    }

    if (userDetails.getSignupdate() == null) {
        errors.rejectValue("signupdate", "error.signupdate-not-specified");
        return;
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstname", "error.firstname-not-specified");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastname", "error.lastname-not-specified");

    if (!StringUtils.isAlphanumeric(userDetails.getFirstname())) {
        errors.rejectValue("firstname", "error.firstname-illegal-characters");
        return;
    }

    if (!StringUtils.isAlphanumeric(userDetails.getLastname())) {
        errors.rejectValue("lastname", "error.lastname-illegal-characters");
        return;
    }

    if (errors.hasErrors())
        userDetails.setPassword("");
}

From source file:org.telscenter.sail.webapp.presentation.web.controllers.teacher.run.CreateRunController.java

/**
 * This method is called after the onBind and onBindAndValidate method. It acts 
 * in the same way as the validator//from  ww  w. j a  v  a  2s.  co m
 * 
 * @see org.springframework.web.servlet.mvc.AbstractWizardFormController#validatePage(java.lang.Object, org.springframework.validation.Errors, int)
 */
@Override
protected void validatePage(Object command, Errors errors, int page) {
    super.validatePage(command, errors, page);
    RunParameters runParameters = (RunParameters) command;

    switch (page) {
    case 0:
        User user = ControllerUtil.getSignedInUser();

        if (!this.projectService.canCreateRun(runParameters.getProject(), user)) {
            errors.rejectValue("project", "not.authorized",
                    "You are not authorized to set up a run with this project.");
        }
        break;
    case 1:
        break;
    case 2:
        if (runParameters.getPeriodNames() == null || runParameters.getPeriodNames().size() == 0) {
            if (runParameters.getManuallyEnteredPeriods() == "") {
                errors.rejectValue("periodNames", "setuprun.error.selectperiods",
                        "You must select one or more periods or manually" + " create your period names.");
            } else {
                // check if manually entered periods is an empty string or just "," If yes, throw error
                if (runParameters.getManuallyEnteredPeriods() == null
                        || StringUtils.trim(runParameters.getManuallyEnteredPeriods()).length() == 0
                        || StringUtils.trim(runParameters.getManuallyEnteredPeriods()).equals(",")) {
                    errors.rejectValue("periodNames", "setuprun.error.selectperiods",
                            "You must select one or more periods or manually" + " create your period names.");
                } else {
                    String[] parsed = StringUtils.split(runParameters.getManuallyEnteredPeriods(), ",");
                    if (parsed.length == 0) {
                        errors.rejectValue("periodNames", "setuprun.error.whitespaceornonalphanumeric",
                                "Manually entered"
                                        + " periods cannot contain whitespace or non-alphanumeric characters.");
                        break;
                    }
                    Set<String> parsedAndTrimmed = new TreeSet<String>();
                    for (String current : parsed) {
                        String trimmed = StringUtils.trim(current);
                        if (trimmed.length() == 0 || StringUtils.contains(trimmed, " ")
                                || !StringUtils.isAlphanumeric(trimmed) || trimmed.equals(",")) {
                            errors.rejectValue("periodNames", "setuprun.error.whitespaceornonalphanumeric",
                                    "Manually entered"
                                            + " periods cannot contain whitespace or non-alphanumeric characters.");
                            break;
                        } else {
                            parsedAndTrimmed.add(trimmed);
                        }
                    }
                    runParameters.setPeriodNames(parsedAndTrimmed);
                    runParameters.setManuallyEnteredPeriods("");
                }
            }
        } else if (runParameters.getManuallyEnteredPeriods() != "") {
            errors.rejectValue("periodNames", "setuprun.error.notsupported",
                    "Selecting both periods AND" + " manually entering periods is not supported.");
        }
        break;
    case 3:
        break;
    case 4:
        break;
    default:
        break;
    }
}

From source file:vn._123pay.bank.VerifyOTPRequestProcessor.java

private String validate(String orderNo, String otp, String numberInput, String checksum) {
    if (StringUtils.isEmpty(orderNo) || StringUtils.isEmpty(otp) || StringUtils.isEmpty(numberInput)
            || StringUtils.isEmpty(checksum)) {
        return Constants.ERROR_6101;
    }/*from   w  w w  .jav a2 s . com*/
    if (orderNo.length() > 17 || !StringUtils.isAlphanumeric(orderNo) || !StringUtils.isNumeric(otp)
            || otp.length() != 8) {
        return Constants.ERROR_6100;
    }

    return Constants.RESPONSE_CODE_1;
}

From source file:vng.paygate.domain.common.NumberUtils.java

public static boolean checkAccountName(String accountName) {
    if ((StringUtils.isBlank(accountName)) || (accountName.length() > 32) || (accountName.length() < 4)) {
        return false;
    }// ww w  . j  ava2 s . c om
    if ((StringUtils.startsWith(accountName, ".")) || (StringUtils.startsWith(accountName, "_"))
            || (StringUtils.endsWith(accountName, ".")) || (StringUtils.endsWith(accountName, "_"))
            || (StringUtils.contains(accountName, "__")) || (StringUtils.contains(accountName, ".."))
            || (StringUtils.contains(accountName, "_.")) || (StringUtils.contains(accountName, "._"))) {
        return false;
    }
    if ((StringUtils.contains(accountName, ".")) || (StringUtils.contains(accountName, "_"))) {
        String accountTemp = StringUtils.remove(accountName, ".");
        accountTemp = StringUtils.remove(accountTemp, "_");
        if (StringUtils.isNumeric(accountTemp)) {
            return true;
        }
    }
    accountName = StringUtils.remove(accountName, ".");
    accountName = StringUtils.remove(accountName, "_");
    if ((!StringUtils.isAlphanumeric(accountName)) || (!StringUtils.isAsciiPrintable(accountName))) {
        return false;
    }
    return true;
}