| java.lang.Object org.ofbiz.base.util.UtilValidate
UtilValidate | public class UtilValidate (Code) | | General input/data validation methods
Utility methods for validating data, especially input.
See detailed description below.
author: David E. Jones version: $Revision: 1.5 $ since: 1.0 since: SUMMARY since:
since: This is a set of meethods for validating input. Functions are provided to validate: since: - U.S. and international phone/fax numbers since: - U.S. ZIP codes(5 or 9 digit postal codes) since: - U.S. Postal Codes(2 letter abbreviations for names of states) since: - U.S. Social Security Numbers(abbreviated as SSNs) since: - email addresses since: - dates(entry of year, month, and day and validity of combined date) since: - credit card numbers since:
since: Supporting utility functions validate that: since: - characters are Letter, Digit, or LetterOrDigit since: - strings are a Signed, Positive, Negative, Nonpositive, or Nonnegative integer since: - strings are a Float or a SignedFloat since: - strings are Alphabetic, Alphanumeric, or Whitespace since: - strings contain an integer within a specified range since:
since: Other utility functions are provided to: since: - remove from a string characters which are/are not in a "bag" of selected characters since: - strip whitespace/leading whitespace from a string since:
since: ============================================================================== since: NOTE: This code was adapted from the Netscape JavaScript form validation code, since: usually found in "FormChek.js". Credit card verification functions Originally since: since: ============================================================================== |
Method Summary | |
public static String | appendCheckDigit(String stPassed) | public static boolean | areEqual(Object obj, Object obj2) | public static boolean | charInString(char c, String s) Returns true if single character c(actually a string) is contained within string s. | public static int | daysInFebruary(int year) Given integer argument year, returns number of days in February of that year. | public static String | getCardType(String ccPassed) | public static int | getLuhnCheckDigit(String stPassed) | public static int | getLuhnSum(String stPassed) | public static boolean | isAlphabetic(String s) Returns true if string s is letters only. | public static boolean | isAlphanumeric(String s) Returns true if string s is English letters (A .. | public static boolean | isAmericanExpress(String cc) | public static boolean | isAnyCard(String ccPassed) | public static boolean | isCardMatch(String cardType, String cardNumberPassed) | public static boolean | isCarteBlanche(String cc) | public static boolean | isContiguousStateCode(String s) Return true if s is a valid contiguous U.S. | public static boolean | isContiguousZipCode(String s) Returns true if string s is a valid contiguous U.S. | public static boolean | isCreditCard(String stPassed) | public static boolean | isDate(String year, String month, String day) isDate returns true if string arguments year, month, and day form a valid date. | public static boolean | isDate(String date) isDate returns true if string argument date forms a valid date. | public static boolean | isDateAfterToday(String date) isDate returns true if string argument date forms a valid date and is after today. | public static boolean | isDay(String s) isDay returns true if string s is a valid day number between 1 and 31. | public static boolean | isDigit(char c) Returns true if character c is a digit (0 .. | public static boolean | isDinersClub(String cc) | public static boolean | isDiscover(String cc) | public static boolean | isEmail(String s) Email address must be of form a@b.c -- in other words:
- there must be at least one character before the @
- there must be at least one character before and after the .
- the characters @ and . | public static boolean | isEmpty(String s) Check whether string s is empty. | public static boolean | isEmpty(Collection c) Check whether collection c is empty. | public static boolean | isEnRoute(String cc) | public static boolean | isFloat(String s) True if string s is an unsigned floating point(real) number.
Also returns true for unsigned integers. | public static boolean | isGiftCard(String stPassed) | public static boolean | isHour(String s) isHour returns true if string s is a valid number between 0 and 23. | public static boolean | isInteger(String s) Returns true if all characters in string s are numbers.
Accepts non-signed integers only. | public static boolean | isIntegerInRange(String s, int a, int b) isIntegerInRange returns true if string s is an integer
within the range of integer arguments a and b, inclusive. | public static boolean | isInternationalPhoneNumber(String s) isInternationalPhoneNumber returns true if string s is a valid
international phone number. | public static boolean | isJCB(String cc) | public static boolean | isLetter(char c) Returns true if character c is an English letter (A .. | public static boolean | isLetterOrDigit(char c) Returns true if character c is a letter or digit. | public static boolean | isMasterCard(String cc) | public static boolean | isMinute(String s) isMinute returns true if string s is a valid number between 0 and 59. | public static boolean | isMonth(String s) isMonth returns true if string s is a valid month number between 1 and 12. | public static boolean | isNegativeInteger(String s) Returns true if string s is an integer < 0. | public static boolean | isNonnegativeInteger(String s) Returns true if string s is an integer >= 0. | public static boolean | isNonpositiveInteger(String s) Returns true if string s is an integer <= 0. | public static boolean | isNotEmpty(String s) Check whether string s is NOT empty. | public static boolean | isNotEmpty(Collection c) Check whether collection c is NOT empty. | public static boolean | isNotPoBox(String s) isNotPoBox returns true if address argument does not contain anything that looks like a a PO Box. | public static boolean | isPositiveInteger(String s) Returns true if string s is an integer > 0. | public static boolean | isSSN(String s) isSSN returns true if string s is a valid U.S. | public static boolean | isSecond(String s) isSecond returns true if string s is a valid number between 0 and 59. | public static boolean | isSignedDouble(String s) True if string s is a signed or unsigned floating point
(real) number. | public static boolean | isSignedFloat(String s) True if string s is a signed or unsigned floating point
(real) number. | public static boolean | isSignedInteger(String s) Returns true if all characters are numbers;
first character is allowed to be + or - as well. | public static boolean | isSignedLong(String s) Returns true if all characters are numbers;
first character is allowed to be + or - as well. | public static boolean | isStateCode(String s) Return true if s is a valid U.S. | public static boolean | isTime(String hour, String minute, String second) isTime returns true if string arguments hour, minute, and second form a valid time. | public static boolean | isTime(String time) isTime returns true if string argument time forms a valid time. | public static boolean | isUSPhoneAreaCode(String s) isUSPhoneAreaCode returns true if string s is a valid U.S. | public static boolean | isUSPhoneMainNumber(String s) isUSPhoneMainNumber returns true if string s is a valid U.S. | public static boolean | isUSPhoneNumber(String s) isUSPhoneNumber returns true if string s is a valid U.S. | public static boolean | isUrl(String s) | public static boolean | isValueLinkCard(String stPassed) | public static boolean | isVisa(String cc) | public static boolean | isWhitespace(String s) Returns true if string s is empty or whitespace characters only. | public static boolean | isYear(String s) isYear returns true if string s is a valid
Year number. | public static boolean | isZipCode(String s) isZIPCode returns true if string s is a valid U.S. | public static String | stripCharsInBag(String s, String bag) Removes all characters which appear in string bag from string s. | public static String | stripCharsNotInBag(String s, String bag) Removes all characters which do NOT appear in string bag from string s. | public static String | stripInitialWhitespace(String s) Removes initial(leading) whitespace characters from s.
Member whitespace(see above) defines which characters are considered whitespace. | public static String | stripWhitespace(String s) Removes all whitespace characters from s.
Member whitespace(see above) defines which characters are considered whitespace. | public static boolean | sumIsMod10(int sum) |
ContiguousUSStateCodes | final public static String ContiguousUSStateCodes(Code) | | Valid contiguous U.S. postal codes
|
SSNDelimiters | final public static String SSNDelimiters(Code) | | non-digit characters which are allowed in Social Security Numbers
|
USStateCodeDelimiter | final public static String USStateCodeDelimiter(Code) | | Delimiter for USStateCodes String
|
USStateCodes | final public static String USStateCodes(Code) | | Valid U.S. Postal Codes for states, territories, armed forces, etc.
See http://www.usps.gov/ncsc/lookups/abbr_state.txt.
|
ZipCodeDelimeter | final public static String ZipCodeDelimeter(Code) | | our preferred delimiter for reformatting ZIP Codes
|
ZipCodeDelimiters | final public static String ZipCodeDelimiters(Code) | | non-digit characters which are allowed in ZIP Codes
|
creditCardDelimiters | final public static String creditCardDelimiters(Code) | | non-digit characters which are allowed in credit card numbers
|
daysInMonth | final public static int[] daysInMonth(Code) | | An array of ints representing the number of days in each month of the year.
Note: February varies depending on the year
|
decimalPointDelimiter | final public static String decimalPointDelimiter(Code) | | decimal point character differs by language and culture
|
defaultEmptyOK | final public static boolean defaultEmptyOK(Code) | | boolean specifying by default whether or not it is okay for a String to be empty
|
digits | final public static String digits(Code) | | digit characters
|
digitsInSocialSecurityNumber | final public static int digitsInSocialSecurityNumber(Code) | | U.S. Social Security Numbers have 9 digits. They are formatted as 123-45-6789.
|
digitsInUSPhoneAreaCode | final public static int digitsInUSPhoneAreaCode(Code) | | |
digitsInUSPhoneMainNumber | final public static int digitsInUSPhoneMainNumber(Code) | | |
digitsInUSPhoneNumber | final public static int digitsInUSPhoneNumber(Code) | | U.S. phone numbers have 10 digits. They are formatted as 123 456 7890 or(123) 456-7890.
|
digitsInZipCode1 | final public static int digitsInZipCode1(Code) | | U.S. ZIP codes have 5 or 9 digits. They are formatted as 12345 or 12345-6789.
|
digitsInZipCode2 | final public static int digitsInZipCode2(Code) | | U.S. ZIP codes have 5 or 9 digits. They are formatted as 12345 or 12345-6789.
|
isContiguousStateCodeMsg | final public static String isContiguousStateCodeMsg(Code) | | |
isContiguousZipCodeMsg | final public static String isContiguousZipCodeMsg(Code) | | |
isCreditCardPrefixMsg | final public static String isCreditCardPrefixMsg(Code) | | |
isCreditCardSuffixMsg | final public static String isCreditCardSuffixMsg(Code) | | |
isDateAfterToday | final public static String isDateAfterToday(Code) | | |
isDatePrefixMsg | final public static String isDatePrefixMsg(Code) | | |
isDateSuffixMsg | final public static String isDateSuffixMsg(Code) | | |
isInternationalPhoneNumberMsg | final public static String isInternationalPhoneNumberMsg(Code) | | |
isSignedDoubleMsg | final public static String isSignedDoubleMsg(Code) | | |
isSignedFloatMsg | final public static String isSignedFloatMsg(Code) | | |
isSignedIntegerMsg | final public static String isSignedIntegerMsg(Code) | | |
isSignedLongMsg | final public static String isSignedLongMsg(Code) | | |
isStateCodeMsg | final public static String isStateCodeMsg(Code) | | |
isUSPhoneAreaCodeMsg | final public static String isUSPhoneAreaCodeMsg(Code) | | |
isUSPhoneMainNumberMsg | final public static String isUSPhoneMainNumberMsg(Code) | | |
letters | final public static String letters(Code) | | letter characters
|
lowercaseLetters | final public static String lowercaseLetters(Code) | | lower-case letter characters
|
phoneNumberDelimiters | final public static String phoneNumberDelimiters(Code) | | non-digit characters which are allowed in phone numbers
|
uppercaseLetters | final public static String uppercaseLetters(Code) | | upper-case letter characters
|
validSSNChars | final public static String validSSNChars(Code) | | characters which are allowed in Social Security Numbers
|
validUSPhoneChars | final public static String validUSPhoneChars(Code) | | characters which are allowed in US phone numbers
|
validWorldPhoneChars | final public static String validWorldPhoneChars(Code) | | characters which are allowed in international phone numbers(a leading + is OK)
|
validZipCodeChars | final public static String validZipCodeChars(Code) | | characters which are allowed in Social Security Numbers
|
whitespace | final public static String whitespace(Code) | | whitespace characters
|
charInString | public static boolean charInString(char c, String s)(Code) | | Returns true if single character c(actually a string) is contained within string s.
|
daysInFebruary | public static int daysInFebruary(int year)(Code) | | Given integer argument year, returns number of days in February of that year.
|
getCardType | public static String getCardType(String ccPassed)(Code) | | Checks to see if the cc number is a valid number for any accepted credit card, and return the name of that type
Parameters: ccPassed - - a string representing a credit card number true, if the credit card number is any valid credit card number for any of the accepted card types, false otherwise |
getLuhnCheckDigit | public static int getLuhnCheckDigit(String stPassed)(Code) | | |
getLuhnSum | public static int getLuhnSum(String stPassed)(Code) | | |
isAlphabetic | public static boolean isAlphabetic(String s)(Code) | | Returns true if string s is letters only.
NOTE: This should handle i18n version to support European characters, etc.
since it now uses Character.isLetter()
|
isAlphanumeric | public static boolean isAlphanumeric(String s)(Code) | | Returns true if string s is English letters (A .. Z, a..z) and numbers only.
NOTE: Need i18n version to support European characters.
This could be tricky due to different character
sets and orderings for various languages and platforms.
|
isAmericanExpress | public static boolean isAmericanExpress(String cc)(Code) | | Checks to see if the cc number is a valid American Express number
Parameters: cc - - a string representing a credit card number; Sample number: 340000000000009(15 digits) true, if the credit card number is a valid American Express number, false otherwise |
isAnyCard | public static boolean isAnyCard(String ccPassed)(Code) | | Checks to see if the cc number is a valid number for any accepted credit card
Parameters: ccPassed - - a string representing a credit card number true, if the credit card number is any valid credit card number for any of the accepted card types, false otherwise |
isCardMatch | public static boolean isCardMatch(String cardType, String cardNumberPassed)(Code) | | Checks to see if the cc number is a valid number for the specified type
Parameters: cardType - - a string representing the credit card type Parameters: cardNumberPassed - - a string representing a credit card number true, if the credit card number is valid for the particular credit card type given in "cardType", false otherwise |
isCarteBlanche | public static boolean isCarteBlanche(String cc)(Code) | | Checks to see if the cc number is a valid Carte Blanche number
Parameters: cc - - a string representing a credit card number; Sample number: 30000000000004(14 digits) true, if the credit card number is a valid Carte Blanche number, false otherwise |
isContiguousStateCode | public static boolean isContiguousStateCode(String s)(Code) | | Return true if s is a valid contiguous U.S. Postal Code (abbreviation for state).
|
isContiguousZipCode | public static boolean isContiguousZipCode(String s)(Code) | | Returns true if string s is a valid contiguous U.S. Zip code. Must be 5 or 9 digits only.
|
isCreditCard | public static boolean isCreditCard(String stPassed)(Code) | | Checks credit card number with Luhn Mod-10 test
Parameters: stPassed - a string representing a credit card number true, if the credit card number passes the Luhn Mod-10 test, false otherwise |
isDate | public static boolean isDate(String year, String month, String day)(Code) | | isDate returns true if string arguments year, month, and day form a valid date.
|
isDate | public static boolean isDate(String date)(Code) | | isDate returns true if string argument date forms a valid date.
|
isDateAfterToday | public static boolean isDateAfterToday(String date)(Code) | | isDate returns true if string argument date forms a valid date and is after today.
|
isDay | public static boolean isDay(String s)(Code) | | isDay returns true if string s is a valid day number between 1 and 31.
|
isDigit | public static boolean isDigit(char c)(Code) | | Returns true if character c is a digit (0 .. 9).
|
isDinersClub | public static boolean isDinersClub(String cc)(Code) | | Checks to see if the cc number is a valid Diners Club number
Parameters: cc - - a string representing a credit card number; Sample number: 30000000000004(14 digits) true, if the credit card number is a valid Diner's Club number, false otherwise |
isDiscover | public static boolean isDiscover(String cc)(Code) | | Checks to see if the cc number is a valid Discover number
Parameters: cc - - a string representing a credit card number; Sample number: 6011000000000004(16 digits) true, if the credit card number is a valid Discover card number, false otherwise |
isEmail | public static boolean isEmail(String s)(Code) | | Email address must be of form a@b.c -- in other words:
- there must be at least one character before the @
- there must be at least one character before and after the .
- the characters @ and . are both required
|
isEmpty | public static boolean isEmpty(String s)(Code) | | Check whether string s is empty.
|
isEmpty | public static boolean isEmpty(Collection c)(Code) | | Check whether collection c is empty.
|
isEnRoute | public static boolean isEnRoute(String cc)(Code) | | Checks to see if the cc number is a valid EnRoute number
Parameters: cc - - a string representing a credit card number; Sample number: 201400000000009(15 digits) true, if the credit card number is a valid enRoute card number, false, otherwise |
isFloat | public static boolean isFloat(String s)(Code) | | True if string s is an unsigned floating point(real) number.
Also returns true for unsigned integers. If you wish
to distinguish between integers and floating point numbers,
first call isInteger, then call isFloat.
Does not accept exponential notation.
|
isGiftCard | public static boolean isGiftCard(String stPassed)(Code) | | Check to see if a card number is a supported Gift Card
Parameters: stPassed - a string representing a gift card true, if the number passed simple checks |
isHour | public static boolean isHour(String s)(Code) | | isHour returns true if string s is a valid number between 0 and 23.
|
isInteger | public static boolean isInteger(String s)(Code) | | Returns true if all characters in string s are numbers.
Accepts non-signed integers only. Does not accept floating
point, exponential notation, etc.
|
isIntegerInRange | public static boolean isIntegerInRange(String s, int a, int b)(Code) | | isIntegerInRange returns true if string s is an integer
within the range of integer arguments a and b, inclusive.
|
isInternationalPhoneNumber | public static boolean isInternationalPhoneNumber(String s)(Code) | | isInternationalPhoneNumber returns true if string s is a valid
international phone number. Must be digits only; any length OK.
May be prefixed by + character.
|
isJCB | public static boolean isJCB(String cc)(Code) | | Checks to see if the cc number is a valid JCB number
Parameters: cc - - a string representing a credit card number; Sample number: 3088000000000009(16 digits) true, if the credit card number is a valid JCB card number, false otherwise |
isLetter | public static boolean isLetter(char c)(Code) | | Returns true if character c is an English letter (A .. Z, a..z).
NOTE: Need i18n version to support European characters.
This could be tricky due to different character
sets and orderings for various languages and platforms.
|
isLetterOrDigit | public static boolean isLetterOrDigit(char c)(Code) | | Returns true if character c is a letter or digit.
|
isMasterCard | public static boolean isMasterCard(String cc)(Code) | | Checks to see if the cc number is a valid Master Card number
Parameters: cc - a string representing a credit card number; Sample number: 5500 0000 0000 0004(16 digits) true, if the credit card number is a valid MasterCard number, false otherwise |
isMinute | public static boolean isMinute(String s)(Code) | | isMinute returns true if string s is a valid number between 0 and 59.
|
isMonth | public static boolean isMonth(String s)(Code) | | isMonth returns true if string s is a valid month number between 1 and 12.
|
isNegativeInteger | public static boolean isNegativeInteger(String s)(Code) | | Returns true if string s is an integer < 0.
|
isNonnegativeInteger | public static boolean isNonnegativeInteger(String s)(Code) | | Returns true if string s is an integer >= 0.
|
isNonpositiveInteger | public static boolean isNonpositiveInteger(String s)(Code) | | Returns true if string s is an integer <= 0.
|
isNotEmpty | public static boolean isNotEmpty(String s)(Code) | | Check whether string s is NOT empty.
|
isNotEmpty | public static boolean isNotEmpty(Collection c)(Code) | | Check whether collection c is NOT empty.
|
isNotPoBox | public static boolean isNotPoBox(String s)(Code) | | isNotPoBox returns true if address argument does not contain anything that looks like a a PO Box.
|
isPositiveInteger | public static boolean isPositiveInteger(String s)(Code) | | Returns true if string s is an integer > 0. NOTE: using the Java Long object for greatest precision
|
isSSN | public static boolean isSSN(String s)(Code) | | isSSN returns true if string s is a valid U.S. Social Security Number. Must be 9 digits.
|
isSecond | public static boolean isSecond(String s)(Code) | | isSecond returns true if string s is a valid number between 0 and 59.
|
isSignedDouble | public static boolean isSignedDouble(String s)(Code) | | True if string s is a signed or unsigned floating point
(real) number. First character is allowed to be + or -.
Also returns true for unsigned integers. If you wish
to distinguish between integers and floating point numbers,
first call isSignedInteger, then call isSignedFloat.
|
isSignedFloat | public static boolean isSignedFloat(String s)(Code) | | True if string s is a signed or unsigned floating point
(real) number. First character is allowed to be + or -.
Also returns true for unsigned integers. If you wish
to distinguish between integers and floating point numbers,
first call isSignedInteger, then call isSignedFloat.
|
isSignedInteger | public static boolean isSignedInteger(String s)(Code) | | Returns true if all characters are numbers;
first character is allowed to be + or - as well.
Does not accept floating point, exponential notation, etc.
|
isSignedLong | public static boolean isSignedLong(String s)(Code) | | Returns true if all characters are numbers;
first character is allowed to be + or - as well.
Does not accept floating point, exponential notation, etc.
|
isStateCode | public static boolean isStateCode(String s)(Code) | | Return true if s is a valid U.S. Postal Code (abbreviation for state).
|
isTime | public static boolean isTime(String hour, String minute, String second)(Code) | | isTime returns true if string arguments hour, minute, and second form a valid time.
|
isTime | public static boolean isTime(String time)(Code) | | isTime returns true if string argument time forms a valid time.
|
isUSPhoneAreaCode | public static boolean isUSPhoneAreaCode(String s)(Code) | | isUSPhoneAreaCode returns true if string s is a valid U.S. Phone Area Code. Must be 3 digits.
|
isUSPhoneMainNumber | public static boolean isUSPhoneMainNumber(String s)(Code) | | isUSPhoneMainNumber returns true if string s is a valid U.S. Phone Main Number. Must be 7 digits.
|
isUSPhoneNumber | public static boolean isUSPhoneNumber(String s)(Code) | | isUSPhoneNumber returns true if string s is a valid U.S. Phone Number. Must be 10 digits.
|
isUrl | public static boolean isUrl(String s)(Code) | | isUrl returns true if the string contains ://
Parameters: s - String to validate true if s contains :// |
isValueLinkCard | public static boolean isValueLinkCard(String stPassed)(Code) | | Check to see if a card number is a valid ValueLink Gift Card
Parameters: stPassed - a string representing a valuelink gift card true, if the number passed simple checks |
isVisa | public static boolean isVisa(String cc)(Code) | | Checks to see if the cc number is a valid Visa number
Parameters: cc - a string representing a credit card number; Sample number: 4111 1111 1111 1111(16 digits) true, if the credit card number is a valid VISA number, false otherwise |
isWhitespace | public static boolean isWhitespace(String s)(Code) | | Returns true if string s is empty or whitespace characters only.
|
isYear | public static boolean isYear(String s)(Code) | | isYear returns true if string s is a valid
Year number. Must be 2 or 4 digits only.
For Year 2000 compliance, you are advised
to use 4-digit year numbers everywhere.
|
isZipCode | public static boolean isZipCode(String s)(Code) | | isZIPCode returns true if string s is a valid U.S. ZIP code. Must be 5 or 9 digits only.
|
stripCharsInBag | public static String stripCharsInBag(String s, String bag)(Code) | | Removes all characters which appear in string bag from string s.
|
stripCharsNotInBag | public static String stripCharsNotInBag(String s, String bag)(Code) | | Removes all characters which do NOT appear in string bag from string s.
|
stripInitialWhitespace | public static String stripInitialWhitespace(String s)(Code) | | Removes initial(leading) whitespace characters from s.
Member whitespace(see above) defines which characters are considered whitespace.
|
stripWhitespace | public static String stripWhitespace(String s)(Code) | | Removes all whitespace characters from s.
Member whitespace(see above) defines which characters are considered whitespace.
|
sumIsMod10 | public static boolean sumIsMod10(int sum)(Code) | | |
|
|