1 24 25 package com.jdon.util; 26 27 28 import java.util.Calendar ; 29 import java.util.Collection ; 30 31 32 68 public class UtilValidate { 69 70 71 public static final boolean defaultEmptyOK = true; 72 73 74 public static final String digits = "0123456789"; 75 76 77 public static final String lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"; 78 79 80 public static final String uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 81 82 83 public static final String letters = lowercaseLetters + uppercaseLetters; 84 85 86 public static final String whitespace = " \t\n\r"; 87 88 89 public static final String decimalPointDelimiter = "."; 90 91 92 public static final String phoneNumberDelimiters = "()- "; 93 94 95 public static final String validUSPhoneChars = digits + phoneNumberDelimiters; 96 97 98 public static final String validWorldPhoneChars = digits + phoneNumberDelimiters + "+"; 99 100 101 public static final String SSNDelimiters = "- "; 102 103 104 public static final String validSSNChars = digits + SSNDelimiters; 105 106 107 public static final int digitsInSocialSecurityNumber = 9; 108 109 110 public static final int digitsInUSPhoneNumber = 10; 111 public static final int digitsInUSPhoneAreaCode = 3; 112 public static final int digitsInUSPhoneMainNumber = 7; 113 114 115 public static final String ZipCodeDelimiters = "-"; 116 117 118 public static final String ZipCodeDelimeter = "-"; 119 120 121 public static final String validZipCodeChars = digits + ZipCodeDelimiters; 122 123 124 public static final int digitsInZipCode1 = 5; 125 126 127 public static final int digitsInZipCode2 = 9; 128 129 130 public static final String creditCardDelimiters = " -"; 131 132 public static final String isNotEmptyMsg = "This field cannot be empty, please enter a value."; 133 public static final String isStateCodeMsg = "The State Code must be a valid two character U.S. state abbreviation(like CA for California)."; 134 public static final String isContiguousStateCodeMsg = "The State Code must be a valid two character U.S. state abbreviation for one of the 48 contiguous United States (like CA for California)."; 135 public static final String isZipCodeMsg = "The ZIP Code must be a 5 or 9 digit U.S. ZIP Code(like 94043)."; 136 public static final String isUSPhoneMsg = "The US Phone must be a 10 digit U.S. phone number(like 415-555-1212)."; 137 public static final String isUSPhoneAreaCodeMsg = "The Phone Number Area Code must be 3 digits."; 138 public static final String isUSPhoneMainNumberMsg = "The Phone Number must be 7 digits."; 139 public static final String isContiguousZipCodeMsg = "Zip Code is not a valid Zip Code for one of the 48 contiguous United States ."; 140 public static final String isInternationalPhoneNumberMsg = "The World Phone must be a valid international phone number."; 141 public static final String isSSNMsg = "The SSN must be a 9 digit U.S. social security number(like 123-45-6789)."; 142 public static final String isEmailMsg = "The Email must be a valid email address(like john@email.com). Please re-enter it now."; 143 public static final String isAnyCardMsg = "The credit card number is not a valid card number."; 144 public static final String isCreditCardPrefixMsg = " is not a valid "; 145 public static final String isCreditCardSuffixMsg = " credit card number."; 146 public static final String isDayMsg = "The Day must be a day number between 1 and 31. "; 147 public static final String isMonthMsg = "The Month must be a month number between 1 and 12. "; 148 public static final String isYearMsg = "The Year must be a 2 or 4 digit year number. "; 149 public static final String isDatePrefixMsg = "The Day, Month, and Year for "; 150 public static final String isDateSuffixMsg = " do not form a valid date. Please reenter them now."; 151 public static final String isHourMsg = "The Hour must be a number between 0 and 23."; 152 public static final String isMinuteMsg = "The Hour must be a number between 0 and 59."; 153 public static final String isSecondMsg = "The Hour must be a number between 0 and 59."; 154 public static final String isTimeMsg = "The Time must be a valid time formed like: HH:MM or HH:MM:SS."; 155 public static final String isDateMsg = "The Date must be a valid date formed like: MM/YY, MM/YYYY, MM/DD/YY, or MM/DD/YYYY."; 156 public static final String isDateAfterToday = "The Date must be a valid date after today, and formed like: MM/YY, MM/YYYY, MM/DD/YY, or MM/DD/YYYY."; 157 public static final String isIntegerMsg = "The Number must be a valid unsigned whole decimal number."; 158 public static final String isSignedIntegerMsg = "The Number must be a valid signed whole decimal number."; 159 public static final String isLongMsg = "The Number must be a valid unsigned whole decimal number."; 160 public static final String isSignedLongMsg = "The Number must be a valid signed whole decimal number."; 161 public static final String isFloatMsg = "The Number must be a valid unsigned decimal number."; 162 public static final String isSignedFloatMsg = "The Number must be a valid signed decimal number."; 163 public static final String isSignedDoubleMsg = "The Number must be a valid signed decimal number."; 164 165 167 public static final int[] daysInMonth = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 168 169 170 public static final String USStateCodeDelimiter = "|"; 171 172 174 public static final String USStateCodes = "AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY|AE|AA|AE|AE|AP"; 175 176 177 public static final String ContiguousUSStateCodes = "AL|AZ|AR|CA|CO|CT|DE|DC|FL|GA|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|VA|WA|WV|WI|WY"; 178 179 public static boolean areEqual(Object obj, Object obj2) { 180 if (obj == null) { 181 return obj2 == null; 182 } else { 183 return obj.equals(obj2); 184 } 185 } 186 187 188 public static boolean isEmpty(String s) { 189 return ((s == null) || (s.length() == 0)); 190 } 191 192 193 194 public static boolean isEmpty(Collection c) { 195 return ((c == null) || (c.size() == 0)); 196 } 197 198 199 public static boolean isNotEmpty(String s) { 200 return ((s != null) && (s.length() > 0)); 201 } 202 203 204 public static boolean isNotEmpty(Collection c) { 205 return ((c != null) && (c.size() > 0)); 206 } 207 208 209 public static boolean isWhitespace(String s) { 210 if (isEmpty(s)) return true; 212 213 for (int i = 0; i < s.length(); i++) { 217 char c = s.charAt(i); 219 220 if (whitespace.indexOf(c) == -1) return false; 221 } 222 return true; 224 } 225 226 227 public static String stripCharsInBag(String s, String bag) { 228 int i; 229 String returnString = ""; 230 231 for (i = 0; i < s.length(); i++) { 234 char c = s.charAt(i); 235 236 if (bag.indexOf(c) == -1) returnString += c; 237 } 238 return returnString; 239 } 240 241 242 public static String stripCharsNotInBag(String s, String bag) { 243 int i; 244 String returnString = ""; 245 246 for (i = 0; i < s.length(); i++) { 249 char c = s.charAt(i); 250 251 if (bag.indexOf(c) != -1) returnString += c; 252 } 253 return returnString; 254 } 255 256 258 public static String stripWhitespace(String s) { 259 return stripCharsInBag(s, whitespace); 260 } 261 262 263 public static boolean charInString(char c, String s) { 264 return (s.indexOf(c) != -1); 265 } 270 271 273 public static String stripInitialWhitespace(String s) { 274 int i = 0; 275 276 while ((i < s.length()) && charInString(s.charAt(i), whitespace)) i++; 277 return s.substring(i); 278 } 280 281 286 public static boolean isLetter(char c) { 287 return Character.isLetter(c); 288 } 289 290 291 public static boolean isDigit(char c) { 292 return Character.isDigit(c); 293 } 294 295 296 public static boolean isLetterOrDigit(char c) { 297 return Character.isLetterOrDigit(c); 298 } 299 300 305 public static boolean isInteger(String s) { 306 if (isEmpty(s)) return defaultEmptyOK; 307 308 for (int i = 0; i < s.length(); i++) { 312 char c = s.charAt(i); 314 315 if (!isDigit(c)) return false; 316 } 317 318 return true; 320 } 321 322 327 public static boolean isSignedInteger(String s) { 328 if (isEmpty(s)) return defaultEmptyOK; 329 330 try { 331 int temp = Integer.parseInt(s); 332 333 return true; 334 } catch (Exception e) { 335 return false; 336 } 337 338 341 343 } 347 348 353 public static boolean isSignedLong(String s) { 354 if (isEmpty(s)) return defaultEmptyOK; 355 356 try { 357 long temp = Long.parseLong(s); 358 359 return true; 360 } catch (Exception e) { 361 return false; 362 } 363 } 364 365 366 public static boolean isPositiveInteger(String s) { 367 if (isEmpty(s)) return defaultEmptyOK; 368 369 try { 370 long temp = Long.parseLong(s); 371 372 if (temp > 0) return true; 373 return false; 374 } catch (Exception e) { 375 return false; 376 } 377 378 } 381 382 383 public static boolean isNonnegativeInteger(String s) { 384 if (isEmpty(s)) return defaultEmptyOK; 385 386 try { 387 int temp = Integer.parseInt(s); 388 389 if (temp >= 0) return true; 390 return false; 391 } catch (Exception e) { 392 return false; 393 } 394 395 } 398 399 400 public static boolean isNegativeInteger(String s) { 401 if (isEmpty(s)) return defaultEmptyOK; 402 403 try { 404 int temp = Integer.parseInt(s); 405 406 if (temp < 0) return true; 407 return false; 408 } catch (Exception e) { 409 return false; 410 } 411 412 } 415 416 417 public static boolean isNonpositiveInteger(String s) { 418 if (isEmpty(s)) return defaultEmptyOK; 419 420 try { 421 int temp = Integer.parseInt(s); 422 423 if (temp <= 0) return true; 424 return false; 425 } catch (Exception e) { 426 return false; 427 } 428 429 } 432 433 441 public static boolean isFloat(String s) { 442 if (isEmpty(s)) return defaultEmptyOK; 443 444 boolean seenDecimalPoint = false; 445 446 if (s.startsWith(decimalPointDelimiter)) return false; 447 448 for (int i = 0; i < s.length(); i++) { 452 char c = s.charAt(i); 454 455 if (c == decimalPointDelimiter.charAt(0)) { 456 if (!seenDecimalPoint) 457 seenDecimalPoint = true; 458 else 459 return false; 460 } else { 461 if (!isDigit(c)) return false; 462 } 463 } 464 return true; 466 } 467 468 475 public static boolean isSignedFloat(String s) { 476 if (isEmpty(s)) return defaultEmptyOK; 477 478 try { 479 float temp = Float.parseFloat(s); 480 481 if (temp <= 0) return true; 482 return false; 483 } catch (Exception e) { 484 return false; 485 } 486 487 } 493 494 501 public static boolean isSignedDouble(String s) { 502 if (isEmpty(s)) return defaultEmptyOK; 503 504 try { 505 double temp = Double.parseDouble(s); 506 507 return true; 508 } catch (Exception e) { 509 return false; 510 } 511 } 512 513 518 public static boolean isAlphabetic(String s) { 519 if (isEmpty(s)) return defaultEmptyOK; 520 521 for (int i = 0; i < s.length(); i++) { 525 char c = s.charAt(i); 527 528 if (!isLetter(c)) 529 return false; 530 } 531 532 return true; 534 } 535 536 542 public static boolean isAlphanumeric(String s) { 543 if (isEmpty(s)) return defaultEmptyOK; 544 545 for (int i = 0; i < s.length(); i++) { 549 char c = s.charAt(i); 551 552 if (!isLetterOrDigit(c)) return false; 553 } 554 555 return true; 557 } 558 559 560 561 562 public static boolean isSSN(String s) { 563 if (isEmpty(s)) return defaultEmptyOK; 564 565 String normalizedSSN = stripCharsInBag(s, SSNDelimiters); 566 567 return (isInteger(normalizedSSN) && normalizedSSN.length() == digitsInSocialSecurityNumber); 568 } 569 570 571 public static boolean isUSPhoneNumber(String s) { 572 if (isEmpty(s)) return defaultEmptyOK; 573 String normalizedPhone = stripCharsInBag(s, phoneNumberDelimiters); 574 575 return (isInteger(normalizedPhone) && normalizedPhone.length() == digitsInUSPhoneNumber); 576 } 577 578 579 public static boolean isUSPhoneAreaCode(String s) { 580 if (isEmpty(s)) return defaultEmptyOK; 581 String normalizedPhone = stripCharsInBag(s, phoneNumberDelimiters); 582 583 return (isInteger(normalizedPhone) && normalizedPhone.length() == digitsInUSPhoneAreaCode); 584 } 585 586 587 public static boolean isUSPhoneMainNumber(String s) { 588 if (isEmpty(s)) return defaultEmptyOK; 589 String normalizedPhone = stripCharsInBag(s, phoneNumberDelimiters); 590 591 return (isInteger(normalizedPhone) && normalizedPhone.length() == digitsInUSPhoneMainNumber); 592 } 593 594 598 public static boolean isInternationalPhoneNumber(String s) { 599 if (isEmpty(s)) return defaultEmptyOK; 600 601 String normalizedPhone = stripCharsInBag(s, phoneNumberDelimiters); 602 603 return isPositiveInteger(normalizedPhone); 604 } 605 606 607 public static boolean isZipCode(String s) { 608 if (isEmpty(s)) return defaultEmptyOK; 609 610 String normalizedZip = stripCharsInBag(s, ZipCodeDelimiters); 611 612 return (isInteger(normalizedZip) && ((normalizedZip.length() == digitsInZipCode1) || (normalizedZip.length() == digitsInZipCode2))); 613 } 614 615 616 public static boolean isContiguousZipCode(String s) { 617 boolean retval = false; 618 if (isZipCode(s)) { 619 if (isEmpty(s)) retval = defaultEmptyOK; 620 else { 621 String normalizedZip = s.substring(0,5); 622 int iZip = Integer.parseInt(normalizedZip); 623 if ((iZip >= 96701 && iZip <= 96898) || (iZip >= 99501 && iZip <= 99950)) retval = false; 624 else retval = true; 625 } 626 } 627 return retval; 628 } 629 630 631 public static boolean isStateCode(String s) { 632 if (isEmpty(s)) return defaultEmptyOK; 633 return ((USStateCodes.indexOf(s) != -1) && (s.indexOf(USStateCodeDelimiter) == -1)); 634 } 635 636 637 public static boolean isContiguousStateCode(String s) { 638 if (isEmpty(s)) return defaultEmptyOK; 639 return ((ContiguousUSStateCodes.indexOf(s) != -1) && (s.indexOf(USStateCodeDelimiter) == -1)); 640 } 641 642 647 public static boolean isEmail(String s) { 648 if (isEmpty(s)) return defaultEmptyOK; 649 650 if (isWhitespace(s)) return false; 652 653 int i = 1; 657 int sLength = s.length(); 658 659 while ((i < sLength) && (s.charAt(i) != '@')) i++; 661 662 if ((i >= sLength - 1) || (s.charAt(i) != '@')) 664 return false; 665 else 666 return true; 667 668 671 } 677 678 684 public static boolean isYear(String s) { 685 if (isEmpty(s)) return defaultEmptyOK; 686 687 if (!isNonnegativeInteger(s)) return false; 688 return ((s.length() == 2) || (s.length() == 4)); 689 } 690 691 694 public static boolean isIntegerInRange(String s, int a, int b) { 695 if (isEmpty(s)) return defaultEmptyOK; 696 if (!isSignedInteger(s)) return false; 699 int num = Integer.parseInt(s); 704 705 return ((num >= a) && (num <= b)); 706 } 707 708 709 public static boolean isMonth(String s) { 710 if (isEmpty(s)) return defaultEmptyOK; 711 return isIntegerInRange(s, 1, 12); 712 } 713 714 715 public static boolean isDay(String s) { 716 if (isEmpty(s)) return defaultEmptyOK; 717 return isIntegerInRange(s, 1, 31); 718 } 719 720 721 public static int daysInFebruary(int year) { 722 return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28); 725 } 726 727 728 public static boolean isHour(String s) { 729 if (isEmpty(s)) return defaultEmptyOK; 730 return isIntegerInRange(s, 0, 23); 731 } 732 733 734 public static boolean isMinute(String s) { 735 if (isEmpty(s)) return defaultEmptyOK; 736 return isIntegerInRange(s, 0, 59); 737 } 738 739 740 public static boolean isSecond(String s) { 741 if (isEmpty(s)) return defaultEmptyOK; 742 return isIntegerInRange(s, 0, 59); 743 } 744 745 746 public static boolean isDate(String year, String month, String day) { 747 if (!(isYear(year) && isMonth(month) && isDay(day))) return false; 749 750 int intYear = Integer.parseInt(year); 751 int intMonth = Integer.parseInt(month); 752 int intDay = Integer.parseInt(day); 753 754 if (intDay > daysInMonth[intMonth - 1]) return false; 756 if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false; 757 return true; 758 } 759 760 761 public static boolean isDate(String date) { 762 if (isEmpty(date)) return defaultEmptyOK; 763 String month; 764 String day; 765 String year; 766 767 int dateSlash1 = date.indexOf("/"); 768 int dateSlash2 = date.lastIndexOf("/"); 769 770 if (dateSlash1 <= 0 || dateSlash1 == dateSlash2) return false; 771 month = date.substring(0, dateSlash1); 772 day = date.substring(dateSlash1 + 1, dateSlash2); 773 year = date.substring(dateSlash2 + 1); 774 775 return isDate(year, month, day); 776 } 777 778 779 public static boolean isDateAfterToday(String date) { 780 if (isEmpty(date)) return defaultEmptyOK; 781 int dateSlash1 = date.indexOf("/"); 782 int dateSlash2 = date.lastIndexOf("/"); 783 784 if (dateSlash1 <= 0) return false; 785 786 java.util.Date passed = null; 787 if (dateSlash1 == dateSlash2) { 788 String month = date.substring(0, dateSlash1); 790 String day = "28"; 791 String year = date.substring(dateSlash1 + 1); 792 if (!isDate(year, month, day)) return false; 793 794 try { 795 int monthInt = Integer.parseInt(month); 796 int yearInt = Integer.parseInt(year); 797 Calendar calendar = Calendar.getInstance(); 798 calendar.set(yearInt, monthInt - 1, 0, 0, 0, 0); 799 calendar.add(Calendar.MONTH, 1); 800 passed = new java.util.Date (calendar.getTime().getTime()); 801 } catch (Exception e) { 802 passed = null; 803 } 804 } else { 805 String month = date.substring(0, dateSlash1); 806 String day = date.substring(dateSlash1 + 1, dateSlash2); 807 String year = date.substring(dateSlash2 + 1); 808 if (!isDate(year, month, day)) return false; 809 passed = UtilDateTime.toDate(month, day, year, "0", "0", "0"); 810 } 811 812 java.util.Date now = UtilDateTime.nowDate(); 813 if (passed != null) { 814 return passed.after(now); 815 } else { 816 return false; 817 } 818 } 819 820 821 public static boolean isTime(String hour, String minute, String second) { 822 if (isHour(hour) && isMinute(minute) && isSecond(second)) 824 return true; 825 else 826 return false; 827 } 828 829 830 public static boolean isTime(String time) { 831 if (isEmpty(time)) return defaultEmptyOK; 832 833 String hour; 834 String minute; 835 String second; 836 837 int timeColon1 = time.indexOf(":"); 838 int timeColon2 = time.lastIndexOf(":"); 839 840 if (timeColon1 <= 0) return false; 841 hour = time.substring(0, timeColon1); 842 if (timeColon1 == timeColon2) { 843 minute = time.substring(timeColon1 + 1); 844 second = "0"; 845 } else { 846 minute = time.substring(timeColon1 + 1, timeColon2); 847 second = time.substring(timeColon2 + 1); 848 } 849 return isTime(hour, minute, second); 850 } 851 852 857 public static boolean isCreditCard(String stPassed) { 858 if (isEmpty(stPassed)) return defaultEmptyOK; 859 String st = stripCharsInBag(stPassed, creditCardDelimiters); 860 861 int sum = 0; 862 int mul = 1; 863 int l = st.length(); 864 865 if (l > 19) return (false); 867 for (int i = 0; i < l; i++) { 868 String digit = st.substring(l - i - 1, l - i); 869 int tproduct = 0; 870 871 try { 872 tproduct = Integer.parseInt(digit, 10) * mul; 873 } catch (Exception e) { 874 Debug.logWarning(e.getMessage()); 875 return false; 876 } 877 if (tproduct >= 10) 878 sum += (tproduct % 10) + 1; 879 else 880 sum += tproduct; 881 if (mul == 1) 882 mul++; 883 else 884 mul--; 885 } 886 892 895 if ((sum % 10) == 0) 896 return true; 897 else 898 return false; 899 } 900 901 906 public static boolean isVisa(String cc) { 907 if (((cc.length() == 16) || (cc.length() == 13)) && (cc.substring(0, 1).equals("4"))) 908 return isCreditCard(cc); 909 return false; 910 } 911 912 917 public static boolean isMasterCard(String cc) { 918 int firstdig = Integer.parseInt(cc.substring(0, 1)); 919 int seconddig = Integer.parseInt(cc.substring(1, 2)); 920 921 if ((cc.length() == 16) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5))) 922 return isCreditCard(cc); 923 return false; 924 925 } 926 927 931 public static boolean isAmericanExpress(String cc) { 932 int firstdig = Integer.parseInt(cc.substring(0, 1)); 933 int seconddig = Integer.parseInt(cc.substring(1, 2)); 934 935 if ((cc.length() == 15) && (firstdig == 3) && ((seconddig == 4) || (seconddig == 7))) 936 return isCreditCard(cc); 937 return false; 938 939 } 940 941 945 public static boolean isDinersClub(String cc) { 946 int firstdig = Integer.parseInt(cc.substring(0, 1)); 947 int seconddig = Integer.parseInt(cc.substring(1, 2)); 948 949 if ((cc.length() == 14) && (firstdig == 3) && ((seconddig == 0) || (seconddig == 6) || (seconddig == 8))) 950 return isCreditCard(cc); 951 return false; 952 } 953 954 958 public static boolean isCarteBlanche(String cc) { 959 return isDinersClub(cc); 960 } 961 962 966 public static boolean isDiscover(String cc) { 967 String first4digs = cc.substring(0, 4); 968 969 if ((cc.length() == 16) && (first4digs.equals("6011"))) 970 return isCreditCard(cc); 971 return false; 972 } 973 974 978 public static boolean isEnRoute(String cc) { 979 String first4digs = cc.substring(0, 4); 980 981 if ((cc.length() == 15) && (first4digs.equals("2014") || first4digs.equals("2149"))) 982 return isCreditCard(cc); 983 return false; 984 } 985 986 990 public static boolean isJCB(String cc) { 991 String first4digs = cc.substring(0, 4); 992 993 if ((cc.length() == 16) && 994 (first4digs.equals("3088") || 995 first4digs.equals("3096") || 996 first4digs.equals("3112") || 997 first4digs.equals("3158") || 998 first4digs.equals("3337") || 999 first4digs.equals("3528"))) 1000 return isCreditCard(cc); 1001 return false; 1002 } 1003 1004 1008 public static boolean isAnyCard(String ccPassed) { 1009 if (isEmpty(ccPassed)) return defaultEmptyOK; 1010 1011 String cc = stripCharsInBag(ccPassed, creditCardDelimiters); 1012 1013 if (!isCreditCard(cc)) return false; 1014 if (isMasterCard(cc) || isVisa(cc) || isAmericanExpress(cc) || isDinersClub(cc) || 1015 isDiscover(cc) || isEnRoute(cc) || isJCB(cc)) 1016 return true; 1017 return false; 1018 } 1019 1020 1024 public static String getCardType(String ccPassed) { 1025 if (isEmpty(ccPassed)) return "Unknown"; 1026 String cc = stripCharsInBag(ccPassed, creditCardDelimiters); 1027 1028 if (!isCreditCard(cc)) return "Unknown"; 1029 1030 if (isMasterCard(cc)) return "MasterCard"; 1031 if (isVisa(cc)) return "Visa"; 1032 if (isAmericanExpress(cc)) return "AmericanExpress"; 1033 if (isDinersClub(cc)) return "DinersClub"; 1034 if (isDiscover(cc)) return "Discover"; 1035 if (isEnRoute(cc)) return "EnRoute"; 1036 if (isJCB(cc)) return "JCB"; 1037 return "Unknown"; 1038 } 1039 1040 1045 public static boolean isCardMatch(String cardType, String cardNumberPassed) { 1046 if (isEmpty(cardType)) return defaultEmptyOK; 1047 if (isEmpty(cardNumberPassed)) return defaultEmptyOK; 1048 String cardNumber = stripCharsInBag(cardNumberPassed, creditCardDelimiters); 1049 1050 if ((cardType.equalsIgnoreCase("VISA")) && (isVisa(cardNumber))) return true; 1051 if ((cardType.equalsIgnoreCase("MASTERCARD")) && (isMasterCard(cardNumber))) return true; 1052 if (((cardType.equalsIgnoreCase("AMERICANEXPRESS")) || (cardType.equalsIgnoreCase("AMEX"))) && (isAmericanExpress(cardNumber))) return true; 1053 if ((cardType.equalsIgnoreCase("DISCOVER")) && (isDiscover(cardNumber))) return true; 1054 if ((cardType.equalsIgnoreCase("JCB")) && (isJCB(cardNumber))) return true; 1055 if (((cardType.equalsIgnoreCase("DINERSCLUB")) || (cardType.equalsIgnoreCase("DINERS"))) && (isDinersClub(cardNumber))) return true; 1056 if ((cardType.equalsIgnoreCase("CARTEBLANCHE")) && (isCarteBlanche(cardNumber))) return true; 1057 if ((cardType.equalsIgnoreCase("ENROUTE")) && (isEnRoute(cardNumber))) return true; 1058 return false; 1059 } 1060 1061 1062 1063 public static boolean isNotPoBox(String s) { 1064 if (isEmpty(s)) return defaultEmptyOK; 1065 1066 1076 String sl = s.toLowerCase(); 1077 if (sl.indexOf("p.o. b") != -1) return false; 1078 if (sl.indexOf("p.o.b") != -1) return false; 1079 if (sl.indexOf("p.o b") != -1) return false; 1080 if (sl.indexOf("p o b") != -1) return false; 1081 if (sl.indexOf("po b") != -1) return false; 1082 if (sl.indexOf("pobox") != -1) return false; 1083 if (sl.indexOf("po#") != -1) return false; 1084 if (sl.indexOf("po #") != -1) return false; 1085 1086 if (sl.indexOf("p.0. b") != -1) return false; 1088 if (sl.indexOf("p.0.b") != -1) return false; 1089 if (sl.indexOf("p.0 b") != -1) return false; 1090 if (sl.indexOf("p 0 b") != -1) return false; 1091 if (sl.indexOf("p0 b") != -1) return false; 1092 if (sl.indexOf("p0box") != -1) return false; 1093 if (sl.indexOf("p0#") != -1) return false; 1094 if (sl.indexOf("p0 #") != -1) return false; 1095 return true; 1096 } 1097} 1098 | Popular Tags |