commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1712874 - in /commons/proper/validator/trunk/src: changes/changes.xml main/java/org/apache/commons/validator/routines/CreditCardValidator.java test/java/org/apache/commons/validator/routines/CreditCardValidatorTest.java
Date Thu, 05 Nov 2015 23:10:45 GMT
Author: sebb
Date: Thu Nov  5 23:10:45 2015
New Revision: 1712874

URL: http://svn.apache.org/viewvc?rev=1712874&view=rev
Log:
VALIDATOR-372 Validate 19 digit VPay (VISA)

Modified:
    commons/proper/validator/trunk/src/changes/changes.xml
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/CreditCardValidator.java
    commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/CreditCardValidatorTest.java

Modified: commons/proper/validator/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/changes/changes.xml?rev=1712874&r1=1712873&r2=1712874&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/changes/changes.xml (original)
+++ commons/proper/validator/trunk/src/changes/changes.xml Thu Nov  5 23:10:45 2015
@@ -43,6 +43,9 @@ The <action> type attribute can be add,u
   <body>
 
   <release version="1.5.0" date="tba" description="tba">
+    <action issue="VALIDATOR-372" type="add" dev="sebb">
+    Validate 19 digit VPay (VISA)
+    </action>
     <action issue="VALIDATOR-375" type="fix" dev="sebb">
     UrlValidator fails on IPv6 URL
     </action>

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/CreditCardValidator.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/CreditCardValidator.java?rev=1712874&r1=1712873&r2=1712874&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/CreditCardValidator.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/CreditCardValidator.java
Thu Nov  5 23:10:45 2015
@@ -98,6 +98,12 @@ public class CreditCardValidator impleme
     public static final long DINERS = 1 << 4;
 
     /**
+     * Option specifying that VPay (Visa) cards are allowed.
+     */
+    public static final long VPAY = 1 << 5;
+
+
+    /**
      * The CreditCardTypes that are allowed to pass validation.
      */
     private final List<CodeValidator> cardTypes = new ArrayList<CodeValidator>();
@@ -125,6 +131,9 @@ public class CreditCardValidator impleme
     /** Visa Card Validator */
     public static final CodeValidator VISA_VALIDATOR = new CodeValidator("^(4)(\\d{12}|\\d{15})$",
LUHN_VALIDATOR);
 
+    /** VPay (Visa) Card Validator */
+    public static final CodeValidator VPAY_VALIDATOR = new CodeValidator("^(4)(\\d{12,18})$",
LUHN_VALIDATOR);
+
     /**
      * Create a new CreditCardValidator with default options.
      */
@@ -145,6 +154,10 @@ public class CreditCardValidator impleme
             this.cardTypes.add(VISA_VALIDATOR);
         }
 
+        if (isOn(options, VPAY)) {
+            this.cardTypes.add(VPAY_VALIDATOR);
+        }
+
         if (isOn(options, AMEX)) {
             this.cardTypes.add(AMEX_VALIDATOR);
         }

Modified: commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/CreditCardValidatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/CreditCardValidatorTest.java?rev=1712874&r1=1712873&r2=1712874&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/CreditCardValidatorTest.java
(original)
+++ commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/CreditCardValidatorTest.java
Thu Nov  5 23:10:45 2015
@@ -40,6 +40,9 @@ public class CreditCardValidatorTest ext
     private static final String ERROR_DISCOVER65 = "6534567890123450"; // FIXME need verified
test data for Discover with "65" prefix
     private static final String VALID_DINERS = "30569309025904";
     private static final String ERROR_DINERS = "30569309025901";
+    private static final String VALID_VPAY = "4370000000000061";
+    private static final String VALID_VPAY2 = "4370000000000012";
+    private static final String ERROR_VPAY = "4370000000000069";
 
     /**
      * Constructor for CreditCardValidatorTest.
@@ -464,6 +467,22 @@ public class CreditCardValidatorTest ext
         assertTrue("Visa Short",      validator.isValid(VALID_SHORT_VISA));
     }
 
+    public void testVPayOption() {
+        CreditCardValidator validator = new CreditCardValidator(CreditCardValidator.VPAY);
+        assertTrue("Valid",           validator.isValid(VALID_VPAY));
+        assertTrue("Valid",           validator.isValid(VALID_VPAY2));
+        assertFalse("Invalid",        validator.isValid(ERROR_VPAY));
+        assertEquals(VALID_VPAY,      validator.validate(VALID_VPAY));
+        assertEquals(VALID_VPAY2,      validator.validate(VALID_VPAY2));
+
+        assertFalse("Amex",           validator.isValid(VALID_AMEX));
+        assertFalse("Diners",         validator.isValid(VALID_DINERS));
+        assertFalse("Discover",       validator.isValid(VALID_DISCOVER));
+        assertFalse("Mastercard",     validator.isValid(VALID_MASTERCARD));
+        assertTrue("Visa",            validator.isValid(VALID_VISA));
+        assertTrue("Visa Short",      validator.isValid(VALID_SHORT_VISA));        
+    }
+
     /**
      * Test using separators
      */    



Mime
View raw message