Author: arunpatidar
Date: Sat Feb 24 11:33:31 2018 New Revision: 1825217 URL: http://svn.apache.org/viewvc?rev=1825217&view=rev Log: Applied fix from trunk for revision: 1825216 === Improved:Update regex used for validating credit cards. (OFBIZ-9761) Thanks Amit Gadaley for your contribution and Michael Brohl for reviewing patch. Modified: ofbiz/ofbiz-framework/branches/release17.12/ (props changed) ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java Propchange: ofbiz/ofbiz-framework/branches/release17.12/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Sat Feb 24 11:33:31 2018 @@ -10,4 +10,4 @@ /ofbiz/branches/json-integration-refactoring:1634077-1635900 /ofbiz/branches/multitenant20100310:921280-927264 /ofbiz/branches/release13.07:1547657 -/ofbiz/ofbiz-framework/trunk:1819499,1819598,1819800,1819805,1819811,1820038,1820262,1820374-1820375,1820441,1820457,1820644,1820658,1820790,1820823,1820949,1820966,1821012,1821036,1821112,1821115,1821144,1821186,1821219,1821226,1821230,1821386,1821600,1821613,1821628,1821965,1822125,1822310,1822377,1822383,1822393,1822882,1823324,1823467,1823562,1823876,1824260,1824314,1824316,1824732,1824803,1824847,1824855,1825192,1825211 +/ofbiz/ofbiz-framework/trunk:1819499,1819598,1819800,1819805,1819811,1820038,1820262,1820374-1820375,1820441,1820457,1820644,1820658,1820790,1820823,1820949,1820966,1821012,1821036,1821112,1821115,1821144,1821186,1821219,1821226,1821230,1821386,1821600,1821613,1821628,1821965,1822125,1822310,1822377,1822383,1822393,1822882,1823324,1823467,1823562,1823876,1824260,1824314,1824316,1824732,1824803,1824847,1824855,1825192,1825211,1825216 Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java?rev=1825217&r1=1825216&r2=1825217&view=diff ============================================================================== --- ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java (original) +++ ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java Sat Feb 24 11:33:31 2018 @@ -1209,14 +1209,14 @@ public final class UtilValidate { /** Checks to see if the cc number is a valid Master Card number * - * @param cc a string representing a credit card number; Sample number: 5500 0000 0000 0004(16 digits) + * @param cc a string representing a credit card number; MasterCard numbers either start with the numbers 51 through 55 or with the numbers 2221 through 2720. All have 16 digits; Sample number: 5500 0000 0000 0004(16 digits) * @return true, if the credit card number is a valid MasterCard number, false otherwise */ public static boolean isMasterCard(String cc) { - int firstdig = Integer.parseInt(cc.substring(0, 1)); - int seconddig = Integer.parseInt(cc.substring(1, 2)); + int first2digs = Integer.parseInt(cc.substring(0, 2)); + int first4digs = Integer.parseInt(cc.substring(0, 4)); - if ((cc.length() == 16) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5))) { + if ((Integer.compare(cc.length(), 16) == 0) && ((first2digs >= 51 && first2digs <= 55) || (first4digs >= 2221 && first4digs <= 2720))) { return isCreditCard(cc); } return false; @@ -1261,13 +1261,14 @@ public final class UtilValidate { } /** Checks to see if the cc number is a valid Discover number - * @param cc - a string representing a credit card number; Sample number: 6011000000000004(16 digits) + * @param cc - a string representing a credit card number; Discover card numbers begin with 6011 or 65. All have 16 digits; Sample number: 6011000000000004(16 digits) * @return true, if the credit card number is a valid Discover card number, false otherwise */ public static boolean isDiscover(String cc) { String first4digs = cc.substring(0, 4); + String first2digs = cc.substring(0, 2); - if ((cc.length() == 16) && ("6011".equals(first4digs))) { + if ((Integer.compare(cc.length(), 16) == 0) && ("6011".equals(first4digs) || "65".equals(first2digs))) { return isCreditCard(cc); } return false; @@ -1287,19 +1288,14 @@ public final class UtilValidate { } /** Checks to see if the cc number is a valid JCB number - * @param cc - a string representing a credit card number; Sample number: 3088000000000009(16 digits) + * @param cc - a string representing a credit card number; JCB cards beginning with 2131 or 1800 have 15 digits. JCB cards beginning with 35 have 16 digits;Sample number: 3088000000000009(16 digits) * @return true, if the credit card number is a valid JCB card number, false otherwise */ public static boolean isJCB(String cc) { String first4digs = cc.substring(0, 4); + String first2digs = cc.substring(0, 2); - if ((cc.length() == 16) && - ("3088".equals(first4digs) || - "3096".equals(first4digs) || - "3112".equals(first4digs) || - "3158".equals(first4digs) || - "3337".equals(first4digs) || - "3528".equals(first4digs))) { + if(((Integer.compare(cc.length(), 16) == 0) && "35".equals(first2digs)) || ((Integer.compare(cc.length(), 15) == 0) && ("2131".equals(first4digs) || "1800".equals(first4digs)))) { return isCreditCard(cc); } return false; |
Free forum by Nabble | Edit this page |