commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgra...@apache.org
Subject cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator EmailValidator.java
Date Sat, 03 May 2003 21:21:05 GMT
dgraham     2003/05/03 14:21:05

  Modified:    validator/src/share/org/apache/commons/validator
                        EmailValidator.java
  Log:
  Simplified isValidUser logic.
  
  Revision  Changes    Path
  1.6       +21 -20    jakarta-commons/validator/src/share/org/apache/commons/validator/EmailValidator.java
  
  Index: EmailValidator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/EmailValidator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EmailValidator.java	3 May 2003 00:08:02 -0000	1.5
  +++ EmailValidator.java	3 May 2003 21:21:04 -0000	1.6
  @@ -119,9 +119,14 @@
   	/**
   	 * <p>Checks if a field has a valid e-mail address.</p>
   	 *
  -	 * @param value The value validation is being performed on.
  +	 * @param value The value validation is being performed on.  A <code>null</code>
  +     * value is considered invalid.
   	 */
   	public boolean isValid(String email) {
  +		if (email == null) {
  +			return false;
  +		}
  +        
   		Perl5Util matchAsciiPat = new Perl5Util();
   		if (!matchAsciiPat.match(LEGAL_ASCII_PATTERN, email)) {
   			return false;
  @@ -137,17 +142,13 @@
   			return false;
   		}
   
  -		if(!isValidUser(emailMatcher.group(1))){
  -            return false;
  -		}
  -
  -		// Check the domain component of the email address
  -		String domain = emailMatcher.group(2);
  -
  -		// check if domain is IP address or symbolic
  -		if(!isValidDomain(domain)){
  -            return false;
  -		}
  +        if (!isValidUser(emailMatcher.group(1))) {
  +        	return false;
  +        }
  +        
  +        if (!isValidDomain(emailMatcher.group(2))) {
  +        	return false;
  +        }
   
   		return true;
   	}
  @@ -185,10 +186,7 @@
        */
   	private boolean isValidUser(String user) {
   		Perl5Util userMatcher = new Perl5Util();
  -		if (userMatcher.match(USER_PATTERN, user)) {
  -			return true;
  -		}
  -		return false;
  +		return userMatcher.match(USER_PATTERN, user);
   	}
   
       /**
  @@ -200,7 +198,9 @@
   			if (ipSegment == null || ipSegment.length() <= 0) {
   				return false;
   			}
  +            
   			int iIpSegment = 0;
  +            
   			try {
   				iIpSegment = Integer.parseInt(ipSegment);
   			} catch (NumberFormatException e) {
  @@ -233,6 +233,7 @@
       				(l >= domain.length())
       					? ""
       					: domain.substring(l);
  +                        
       			i++;
       		}
       	}
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message