本文整理汇总了Java中org.apache.commons.validator.GenericValidator.isEmail方法的典型用法代码示例。如果您正苦于以下问题:Java GenericValidator.isEmail方法的具体用法?Java GenericValidator.isEmail怎么用?Java GenericValidator.isEmail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.validator.GenericValidator
的用法示例。
在下文中一共展示了GenericValidator.isEmail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateEmail
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
/**
* Checks if a field has a valid e-mail address.
*
* @param bean The bean validation is being performed on.
* @param va The <code>ValidatorAction</code> that is currently being performed.
* @param field The <code>Field</code> object associated with the current
* field being validated.
* @param errors The <code>ActionMessages</code> object to add errors to if any
* validation errors occur.
* @param validator The <code>Validator</code> instance, used to access
* other field values.
* @param request Current request object.
* @return True if valid, false otherwise.
*/
public static boolean validateEmail(Object bean,
ValidatorAction va, Field field,
ActionMessages errors,
Validator validator,
HttpServletRequest request) {
String value = null;
if (isString(bean)) {
value = (String) bean;
} else {
value = ValidatorUtils.getValueAsString(bean, field.getProperty());
}
if (!GenericValidator.isBlankOrNull(value) && !GenericValidator.isEmail(value)) {
errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
return false;
} else {
return true;
}
}
示例2: validateEmail
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
/**
* Checks if a field has a valid e-mail address.
*
* @param bean The bean validation is being performed on.
* @param va The <code>ValidatorAction</code> that is currently
* being performed.
* @param field The <code>Field</code> object associated with the
* current field being validated.
* @param errors The <code>ActionMessages</code> object to add errors
* to if any validation errors occur.
* @param validator The <code>Validator</code> instance, used to access
* other field values.
* @param request Current request object.
* @return True if valid, false otherwise.
*/
public static boolean validateEmail(Object bean, ValidatorAction va,
Field field, ActionMessages errors, Validator validator,
HttpServletRequest request) {
String value = null;
value = evaluateBean(bean, field);
if (!GenericValidator.isBlankOrNull(value)
&& !GenericValidator.isEmail(value)) {
errors.add(field.getKey(),
Resources.getActionMessage(validator, request, va, field));
return false;
} else {
return true;
}
}
示例3: validate
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
public void validate(UpdateAccountForm form, Errors errors) {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required");
if (!errors.hasErrors()) {
//is this a valid email address?
if (!GenericValidator.isEmail(form.getEmailAddress())) {
errors.rejectValue("emailAddress", "emailAddress.invalid");
}
//check email address to see if it is already in use by another customer
Customer customerMatchingNewEmail = customerService.readCustomerByEmail(form.getEmailAddress());
if (customerMatchingNewEmail != null && !CustomerState.getCustomer().getId().equals(customerMatchingNewEmail.getId())) {
//customer found with new email entered, and it is not the current customer
errors.rejectValue("emailAddress", "emailAddress.used");
}
}
}
示例4: validate
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
public boolean validate(CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks,
ValidatorContext context)
{
String value = null;
value = getValueAsString(source, propertyName);
if (!GenericValidator.isBlankOrNull(value) && !GenericValidator.isEmail(value))
{
JobEntryValidatorUtils.addFailureRemark(source, propertyName, VALIDATOR_NAME, remarks, JobEntryValidatorUtils
.getLevelOnFail(context, VALIDATOR_NAME));
return false;
} else
{
return true;
}
}
示例5: validate
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
public void validate(Customer customer, String password, String passwordConfirm, Errors errors) {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwordConfirm", "passwordConfirm.required");
errors.pushNestedPath("customer");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required");
errors.popNestedPath();
if (errors.hasErrors()){
if (!passwordConfirm.equals(password)) {
errors.rejectValue("passwordConfirm", "invalid");
}
if (!customer.getFirstName().matches(validNameRegex)) {
errors.rejectValue("firstName", "firstName.invalid", null, null);
}
if (!customer.getLastName().matches(validNameRegex)) {
errors.rejectValue("lastName", "lastName.invalid", null, null);
}
if (!customer.getPassword().matches(validPasswordRegex)) {
errors.rejectValue("password", "password.invalid", null, null);
}
if (!password.equals(passwordConfirm)) {
errors.rejectValue("password", "passwordConfirm.invalid", null, null);
}
if (!GenericValidator.isEmail(customer.getEmailAddress())) {
errors.rejectValue("emailAddress", "emailAddress.invalid", null, null);
}
}
}
示例6: validate
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
public void validate(Object obj, Errors errors, boolean useEmailForUsername) {
RegisterCustomerForm form = (RegisterCustomerForm) obj;
Customer customerFromDb = customerService.readCustomerByUsername(form.getCustomer().getUsername());
if (customerFromDb != null) {
if (useEmailForUsername) {
errors.rejectValue("customer.emailAddress", "emailAddress.used", null, null);
} else {
errors.rejectValue("customer.username", "username.used", null, null);
}
}
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwordConfirm", "passwordConfirm.required");
errors.pushNestedPath("customer");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required");
errors.popNestedPath();
if (!errors.hasErrors()) {
if (!form.getPassword().matches(getValidatePasswordExpression())) {
errors.rejectValue("password", "password.invalid", null, null);
}
if (!form.getPassword().equals(form.getPasswordConfirm())) {
errors.rejectValue("password", "passwordConfirm.invalid", null, null);
}
if (!GenericValidator.isEmail(form.getCustomer().getEmailAddress())) {
errors.rejectValue("customer.emailAddress", "emailAddress.invalid", null, null);
}
}
}
示例7: validate
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
public void validate(Object obj, Errors errors) {
CheckoutForm checkoutForm = (CheckoutForm) obj;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.addressLine1", "addressLine1.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.phonePrimary", "phone.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.city", "city.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.postalCode", "postalCode.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.firstName", "firstName.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.lastName", "lastName.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shippingAddress.addressLine1", "addressLine1.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shippingAddress.city", "city.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shippingAddress.postalCode", "postalCode.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shippingAddress.firstName", "firstName.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shippingAddress.lastName", "lastName.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardNumber", "creditCardNumber.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardCvvCode", "creditCardCvvCode.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardExpMonth", "creditCardExpMonth.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardExpYear", "creditCardExpYear.required");
if (!errors.hasErrors()) {
if (!GenericValidator.isEmail(checkoutForm.getEmailAddress())) {
errors.rejectValue("emailAddress", "emailAddress.invalid", null, null);
}
}
}
示例8: checkRecipientAddress
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
@Override
public void checkRecipientAddress(Address address) throws InvalidAddessException {
LOG.fine("Checking recipient address: " + address.getAddress());
if (GenericValidator.isBlankOrNull(address.getAddress()) ||
!GenericValidator.isEmail(address.getAddress())) {
throw new InvalidAddessException("Recipient address must be a valid email address");
}
}
示例9: loadUserByUsername
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
@Override
public UserDetails loadUserByUsername(String userName)
throws UsernameNotFoundException, DataAccessException {
try {
boolean isMail = GenericValidator.isEmail(userName);
User user = isMail ? userDao.findByEmail(userName) : userDao.findByName(userName);
return assembler.buildUserFromUserEntity(user);
} catch (UserNotFoundException ex) {
throw new UsernameNotFoundException("user not found");
}
}
示例10: isTextTestable
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
/**
*
* @param extractedText
* @return
*/
protected boolean isTextTestable(String extractedText) {
if (StringUtils.isBlank(extractedText)){
return false;
}
String textToTest = StringUtils.trim(extractedText);
Matcher m = nonAlphanumericPattern.matcher(textToTest);
return !m.matches() &&
!GenericValidator.isEmail(textToTest) &&
!GenericValidator.isUrl(textToTest);
}
示例11: validate
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
public boolean validate( CheckResultSourceInterface source, String propertyName,
List<CheckResultInterface> remarks, ValidatorContext context ) {
String value = null;
value = ValidatorUtils.getValueAsString( source, propertyName );
if ( !GenericValidator.isBlankOrNull( value ) && !GenericValidator.isEmail( value ) ) {
JobEntryValidatorUtils.addFailureRemark(
source, propertyName, VALIDATOR_NAME, remarks, JobEntryValidatorUtils.getLevelOnFail(
context, VALIDATOR_NAME ) );
return false;
} else {
return true;
}
}
示例12: validateEmailOrBlank
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
public static boolean validateEmailOrBlank(Object bean, Field field) {
String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
return GenericValidator.isBlankOrNull(value) || GenericValidator.isEmail(value);
}
示例13: validateString
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
private List<? extends ErrorReport> validateString( Class<?> klass, Object propertyObject, Property property )
{
List<ErrorReport> errorReports = new ArrayList<>();
// TODO How should empty strings be handled? they are not valid color, password, url, etc of course.
if ( !String.class.isInstance( propertyObject ) || StringUtils.isEmpty( propertyObject ) )
{
return errorReports;
}
String value = (String) propertyObject;
// check column max length
if ( value.length() > property.getLength() )
{
errorReports.add( new ErrorReport( klass, ErrorCode.E4001, property.getName(), property.getLength(), value.length() )
.setErrorKlass( property.getKlass() ).setErrorProperty( property.getName() ) );
return errorReports;
}
if ( value.length() < property.getMin() || value.length() > property.getMax() )
{
errorReports.add( new ErrorReport( klass, ErrorCode.E4002, property.getName(), property.getMin(), property.getMax(), value.length() )
.setErrorKlass( property.getKlass() ).setErrorProperty( property.getName() ) );
}
if ( PropertyType.EMAIL == property.getPropertyType() && !GenericValidator.isEmail( value ) )
{
errorReports.add( new ErrorReport( klass, ErrorCode.E4003, property.getName(), value )
.setErrorKlass( property.getKlass() ).setErrorProperty( property.getName() ) );
}
else if ( PropertyType.URL == property.getPropertyType() && !isUrl( value ) )
{
errorReports.add( new ErrorReport( klass, ErrorCode.E4004, property.getName(), value )
.setErrorKlass( property.getKlass() ).setErrorProperty( property.getName() ) );
}
else if ( !BCRYPT_PATTERN.matcher( value ).matches() && PropertyType.PASSWORD == property.getPropertyType() && !ValidationUtils.passwordIsValid( value ) )
{
errorReports.add( new ErrorReport( klass, ErrorCode.E4005, property.getName(), value )
.setErrorKlass( property.getKlass() ).setErrorProperty( property.getName() ) );
}
else if ( PropertyType.COLOR == property.getPropertyType() && !ValidationUtils.isValidHexColor( value ) )
{
errorReports.add( new ErrorReport( klass, ErrorCode.E4006, property.getName(), value )
.setErrorKlass( property.getKlass() ).setErrorProperty( property.getName() ) );
}
/* TODO add proper validation for both Points and Polygons, ValidationUtils only supports points at this time
if ( PropertyType.GEOLOCATION == property.getPropertyType() && !ValidationUtils.coordinateIsValid( value ) )
{
validationViolations.add( new ValidationViolation( "Value is not a valid coordinate pair [lon, lat]." ) );
}
*/
return errorReports;
}
示例14: validateString
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
private Collection<? extends ValidationViolation> validateString( Object object, Property property )
{
List<ValidationViolation> validationViolations = new ArrayList<>();
// TODO How should empty strings be handled? they are not valid color, password, url, etc of course.
if ( !String.class.isInstance( object ) || StringUtils.isEmpty( object ) )
{
return validationViolations;
}
String value = (String) object;
// check column max length
if ( value.length() > property.getLength() )
{
validationViolations.add( new ValidationViolation( property.getName(), "Maximum length for property is "
+ property.getLength() + ", length is " + value.length(), value ) );
return validationViolations;
}
if ( value.length() < property.getMin() || value.length() > property.getMax() )
{
validationViolations.add( new ValidationViolation( property.getName(), "Allowed range for length ["
+ property.getMin() + ", " + property.getMax() + "], length is " + value.length(), value ) );
}
if ( PropertyType.EMAIL == property.getPropertyType() && !GenericValidator.isEmail( value ) )
{
validationViolations.add( new ValidationViolation( property.getName(), "Not a valid email.", value ) );
}
else if ( PropertyType.URL == property.getPropertyType() && !isUrl( value ) )
{
validationViolations.add( new ValidationViolation( property.getName(), "Not a valid URL.", value ) );
}
else if ( PropertyType.PASSWORD == property.getPropertyType() && !ValidationUtils.passwordIsValid( value ) )
{
validationViolations.add( new ValidationViolation( property.getName(), "Not a valid password.", value ) );
}
else if ( PropertyType.COLOR == property.getPropertyType() && !ValidationUtils.isValidHexColor( value ) )
{
validationViolations.add( new ValidationViolation( property.getName(), "Not a valid hex color.", value ) );
}
/* TODO add proper validation for both Points and Polygons, ValidationUtils only supports points at this time
if ( PropertyType.GEOLOCATION == property.getPropertyType() && !ValidationUtils.coordinateIsValid( value ) )
{
validationViolations.add( new ValidationViolation( "Value is not a valid coordinate pair [lon, lat]." ) );
}
*/
return validationViolations;
}
示例15: validateEMail
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
public void validateEMail(String fieldName, String email) throws ValidationException {
if (email == null || !GenericValidator.isEmail(email)) {
throw new ValidationException(fieldName, "This field must be a valid email.");
}
}