Package com.liferay.portal.kernel.util
Class Validator
Object
com.liferay.portal.kernel.util.Validator
Provides utility methods related to data validation and format checking.
- Author:
- Brian Wing Shun Chan, Alysa Carver
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanequalsSorted(boolean[] booleanArray1, boolean[] booleanArray2) Returnstrueif the boolean arrays are equal.static booleanequalsSorted(byte[] byteArray1, byte[] byteArray2) Returnstrueif the byte arrays are equal.static booleanequalsSorted(char[] charArray1, char[] charArray2) Returnstrueif the char arrays are equal.static booleanequalsSorted(double[] doubleArray1, double[] doubleArray2) Returnstrueif the double arrays are equal.static booleanequalsSorted(float[] floatArray1, float[] floatArray2) Returnstrueif the float arrays are equal.static booleanequalsSorted(int[] intArray1, int[] intArray2) Returnstrueif the int arrays are equal.static booleanequalsSorted(long[] longArray1, long[] longArray2) Returnstrueif the long arrays are equal.static booleanequalsSorted(short[] shortArray1, short[] shortArray2) Returnstrueif the short arrays are equal.static booleanequalsSorted(Object[] objArray1, Object[] objArray2) Returnstrueif the object arrays are equal.static booleanReturnstrueif the string is an email address.static booleanisAlphanumericName(String name) Returnstrueif the string is an alphanumeric name, meaning it contains nothing but English letters, numbers, and spaces.static booleanisAscii(char c) Returnstrueif the character is in the ASCII character set.static booleanstatic booleanstatic booleanisChar(char c) Returnstrueif the character is an upper or lower case English letter.static booleanReturnstrueif string consists only of upper and lower case English letters.static booleanReturnstrueif the string contains content.static booleanisDate(int month, int day, int year) Returnstrueif the date is valid in the Gregorian calendar.static booleanisDigit(char c) Returnstrueif the character is a digit between 0 and 9 (inclusive).static booleanReturnstrueif the string consists of only digits between 0 and 9 (inclusive).static booleanReturnstrueif the string is a valid domain name.static booleanisEmailAddress(String emailAddress) Returnstrueif the string is a valid email address.static booleanisEmailAddressSpecialChar(char c) Returnstrueif the character is a special character in an email address.static booleanisFileExtension(String fileExtension) Returnstrueif the file extension is valid.static booleanisFileName(String name) static booleanisFilePath(String path, boolean parentDirAllowed) static booleanisGregorianDate(int month, int day, int year) Returnstrueif the date is valid in the Gregorian calendar.static booleanReturnstrueif the string is a hexidecimal number.static booleanisHostName(String name) Returnstrueif the string is a valid host name.static booleanReturnstrueif the string is an HTML document.static booleanisIPAddress(String ipAddress) Returnstrueif the string is a valid IPv4 or IPv6 IP address.static booleanisIPv4Address(String ipAddress) Returnstrueif the string is a valid IPv4 IP address.static booleanisIPv6Address(String ipAddress) Returnstrueif the string is a valid IPv6 IP address.static booleanisJulianDate(int month, int day, int year) Returnstrueif the date is valid in the Julian calendar.static booleanReturnstrueif the string contains a valid number according to the Luhn algorithm, commonly used to validate credit card numbers.static booleanReturnstrueif the string is a name, meaning it contains nothing but English letters and spaces.static booleanReturnstrueif the long number object is notnull, meaning it is neither anullreference or zero.static booleanReturnstrueif the object is notnull, using the rules fromisNotNull(Long)orisNotNull(String)if the object is one of these types.static booleanReturnstrueif the string is notnull, meaning it is not anullreference, an empty string, whitespace, or the string "null", with or without leading or trailing whitespace.static booleanReturnstrueif the long number object isnull, meaning it is either anullreference or zero.static booleanReturnstrueif the object isnull, using the rules fromisNull(Long)orisNull(String)if the object is one of these types.static booleanReturnstrueif the string isnull, meaning it is anullreference, an empty string, whitespace, or the string "null", with or without leading or trailing whitespace.static booleanReturnstrueif the string is a decimal integer number, meaning it contains nothing but decimal digits.static booleanisPassword(String password) Returnstrueif the string is a valid password, meaning it is at least four characters long and contains only letters and decimal digits.static booleanisPhoneNumber(String phoneNumber) Returnstrueif the string is a valid phone number.static booleanstatic booleanReturnstrueif the string is a valid URL based on the rules inURL.static booleanReturnstrueif the string is a valid URL based on the rules inURL.static booleanisVariableName(String variableName) Returnstrueif the string is a valid variable name in Java.static booleanReturnstrueif the string is a valid variable term, meaning it begins with "[$" and ends with "$]".static booleanisWhitespace(char c) Returnstrueif the character is whitespace, meaning it is either thenullcharacter '0' or whitespace according toCharacter.isWhitespace(char).static booleanReturnstrueif the string is an XML document.
-
Constructor Details
-
Validator
public Validator()
-
-
Method Details
-
equalsSorted
public static boolean equalsSorted(boolean[] booleanArray1, boolean[] booleanArray2) Returnstrueif the boolean arrays are equal.- Parameters:
booleanArray1- the first boolean arraybooleanArray2- the second boolean array- Returns:
trueif the booleans arrays are equal;falseotherwise
-
equalsSorted
public static boolean equalsSorted(byte[] byteArray1, byte[] byteArray2) Returnstrueif the byte arrays are equal.- Parameters:
byteArray1- the first byte arraybyteArray2- the second byte array- Returns:
trueif the byte arrays are equal;falseotherwise
-
equalsSorted
public static boolean equalsSorted(char[] charArray1, char[] charArray2) Returnstrueif the char arrays are equal.- Parameters:
charArray1- the first char arraycharArray2- the second char array- Returns:
trueif the char arrays are equal;falseotherwise
-
equalsSorted
public static boolean equalsSorted(double[] doubleArray1, double[] doubleArray2) Returnstrueif the double arrays are equal.- Parameters:
doubleArray1- the first double arraydoubleArray2- the second double array- Returns:
trueif the double arrays are equal;falseotherwise
-
equalsSorted
public static boolean equalsSorted(float[] floatArray1, float[] floatArray2) Returnstrueif the float arrays are equal.- Parameters:
floatArray1- the first float arrayfloatArray2- the second char array- Returns:
trueif the float arrays are equal;falseotherwise
-
equalsSorted
public static boolean equalsSorted(int[] intArray1, int[] intArray2) Returnstrueif the int arrays are equal.- Parameters:
intArray1- the first int arrayintArray2- the second int array- Returns:
trueif the int arrays are equal;falseotherwise
-
equalsSorted
public static boolean equalsSorted(long[] longArray1, long[] longArray2) Returnstrueif the long arrays are equal.- Parameters:
longArray1- the first long arraylongArray2- the second long array- Returns:
trueif the long arrays are equal;falseotherwise
-
equalsSorted
Returnstrueif the object arrays are equal.- Parameters:
objArray1- the first object arrayobjArray2- the second object array- Returns:
trueif the object arrays are equal;falseotherwise
-
equalsSorted
public static boolean equalsSorted(short[] shortArray1, short[] shortArray2) Returnstrueif the short arrays are equal.- Parameters:
shortArray1- the first short arrayshortArray2- the second short array- Returns:
trueif the short arrays are equal;falseotherwise
-
isAddress
Returnstrueif the string is an email address. The only requirements are that the string consist of two parts separated by an @ symbol, and that it contain no whitespace.- Parameters:
address- the string to check- Returns:
trueif the string is an email address;falseotherwise
-
isAlphanumericName
Returnstrueif the string is an alphanumeric name, meaning it contains nothing but English letters, numbers, and spaces.- Parameters:
name- the string to check- Returns:
trueif the string is an Alphanumeric name;falseotherwise
-
isAscii
public static boolean isAscii(char c) Returnstrueif the character is in the ASCII character set. This includes characters with integer values between 32 and 126 (inclusive).- Parameters:
c- the character to check- Returns:
trueif the character is in the ASCII character set;falseotherwise
-
isBlank
-
isBoolean
-
isChar
public static boolean isChar(char c) Returnstrueif the character is an upper or lower case English letter.- Parameters:
c- the character to check- Returns:
trueif the character is an upper or lower case English letter;falseotherwise
-
isChar
Returnstrueif string consists only of upper and lower case English letters.- Parameters:
s- the string to check- Returns:
trueif the string consists only of upper and lower case English letters
-
isContent
Returnstrueif the string contains content. The only requirement is that it contain content that is not whitespace.- Parameters:
s- the string to check- Returns:
trueif the string contains content;falseotherwise
-
isDate
public static boolean isDate(int month, int day, int year) Returnstrueif the date is valid in the Gregorian calendar.- Parameters:
month- the month to checkday- the day to checkyear- the year to check- Returns:
trueif the date is valid in the Gregorian calendar;falseotherwise
-
isDigit
public static boolean isDigit(char c) Returnstrueif the character is a digit between 0 and 9 (inclusive).- Parameters:
c- the character to check- Returns:
trueif the character is a digit between 0 and 9 (inclusive);falseotherwise
-
isDigit
Returnstrueif the string consists of only digits between 0 and 9 (inclusive).- Parameters:
s- the string to check- Returns:
trueif the string consists of only digits between 0 and 9 (inclusive);falseotherwise
-
isDomain
Returnstrueif the string is a valid domain name. See RFC-1034 (section 3), RFC-1123 (section 2.1), and RFC-952 (section B. Lexical grammar).- Parameters:
domainName- the string to check- Returns:
trueif the string is a valid domain name;falseotherwise
-
isEmailAddress
Returnstrueif the string is a valid email address.- Parameters:
emailAddress- the string to check- Returns:
trueif the string is a valid email address;falseotherwise
-
isEmailAddressSpecialChar
public static boolean isEmailAddressSpecialChar(char c) Returnstrueif the character is a special character in an email address.- Parameters:
c- the character to check- Returns:
trueif the character is a special character in an email address;falseotherwise
-
isFileExtension
Returnstrueif the file extension is valid.- Parameters:
fileExtension- string to check- Returns:
trueif the extension is valid;falseotherwise
-
isFileName
-
isFilePath
-
isGregorianDate
public static boolean isGregorianDate(int month, int day, int year) Returnstrueif the date is valid in the Gregorian calendar.- Parameters:
month- the month (0-based, meaning 0 for January)day- the day of the monthyear- the year- Returns:
trueif the date is valid;falseotherwise
-
isHex
Returnstrueif the string is a hexidecimal number. At present the only requirement is that the string is notnull; it does not actually check the format of the string.- Parameters:
s- the string to check- Returns:
trueif the string is a hexidecimal number;falseotherwise- See Also:
-
isHostName
Returnstrueif the string is a valid host name.- Parameters:
name- the string to check- Returns:
trueif the string is a valid host name;falseotherwise
-
isHTML
Returnstrueif the string is an HTML document. The only requirement is that it contain the opening and closing html tags.- Parameters:
s- the string to check- Returns:
trueif the string is an HTML document;falseotherwise
-
isIPAddress
Returnstrueif the string is a valid IPv4 or IPv6 IP address.- Parameters:
ipAddress- the string to check- Returns:
trueif the string is a valid IPv4 or IPv6 IP address;falseotherwise
-
isIPv4Address
Returnstrueif the string is a valid IPv4 IP address.- Parameters:
ipAddress- the string to check- Returns:
trueif the string is a valid IPv4 IP address;falseotherwise
-
isIPv6Address
Returnstrueif the string is a valid IPv6 IP address.- Parameters:
ipAddress- the string to check- Returns:
trueif the string is a valid IPv6 IP address;falseotherwise
-
isJulianDate
public static boolean isJulianDate(int month, int day, int year) Returnstrueif the date is valid in the Julian calendar.- Parameters:
month- the month (0-based, meaning 0 for January)day- the day of the monthyear- the year- Returns:
trueif the date is valid in the Julian calendar;falseotherwise
-
isLUHN
Returnstrueif the string contains a valid number according to the Luhn algorithm, commonly used to validate credit card numbers.- Parameters:
number- the string to check- Returns:
trueif the string contains a valid number according to the Luhn algorithm;falseotherwise
-
isName
Returnstrueif the string is a name, meaning it contains nothing but English letters and spaces.- Parameters:
name- the string to check- Returns:
trueif the string is a name;falseotherwise
-
isNotNull
Returnstrueif the long number object is notnull, meaning it is neither anullreference or zero.- Parameters:
l- the long number object to check- Returns:
trueif the long number object is notnull;falseotherwise
-
isNotNull
Returnstrueif the object is notnull, using the rules fromisNotNull(Long)orisNotNull(String)if the object is one of these types.- Parameters:
object- the object to check- Returns:
trueif the object is notnull;falseotherwise
-
isNotNull
Returnstrueif the string is notnull, meaning it is not anullreference, an empty string, whitespace, or the string "null", with or without leading or trailing whitespace.- Parameters:
s- the string to check- Returns:
trueif the string is notnull;falseotherwise
-
isNull
Returnstrueif the long number object isnull, meaning it is either anullreference or zero.- Parameters:
l- the long number object to check- Returns:
trueif the long number object isnull;falseotherwise
-
isNull
Returnstrueif the object isnull, using the rules fromisNull(Long)orisNull(String)if the object is one of these types.- Parameters:
object- the object to check- Returns:
trueif the object isnull;falseotherwise
-
isNull
Returnstrueif the string isnull, meaning it is anullreference, an empty string, whitespace, or the string "null", with or without leading or trailing whitespace.- Parameters:
s- the string to check- Returns:
trueif the string isnull;falseotherwise
-
isNumber
Returnstrueif the string is a decimal integer number, meaning it contains nothing but decimal digits.- Parameters:
number- the string to check- Returns:
trueif the string is a decimal integer number;falseotherwise
-
isPassword
Returnstrueif the string is a valid password, meaning it is at least four characters long and contains only letters and decimal digits.- Parameters:
password- the string to check- Returns:
trueif the string is a valid password;falseotherwise
-
isPhoneNumber
Returnstrueif the string is a valid phone number. The only requirement is that there are decimal digits in the string; length and format are not checked.- Parameters:
phoneNumber- the string to check- Returns:
trueif the string is a valid phone number;falseotherwise
-
isUri
-
isUrl
Returnstrueif the string is a valid URL based on the rules inURL.- Parameters:
url- the string to check- Returns:
trueif the string is a valid URL;falseotherwise
-
isUrl
Returnstrueif the string is a valid URL based on the rules inURL. This method can also validate root relative URLs.- Parameters:
url- the string to checkacceptRootRelative- whether a root relative URL should be accepted- Returns:
trueif the string is a valid URL;falseotherwise
-
isVariableName
Returnstrueif the string is a valid variable name in Java.- Parameters:
variableName- the string to check- Returns:
trueif the string is a valid variable name in Java;falseotherwise
-
isVariableTerm
Returnstrueif the string is a valid variable term, meaning it begins with "[$" and ends with "$]".- Parameters:
s- the string to check- Returns:
trueif the string is a valid variable term;falseotherwise
-
isWhitespace
public static boolean isWhitespace(char c) Returnstrueif the character is whitespace, meaning it is either thenullcharacter '0' or whitespace according toCharacter.isWhitespace(char).- Parameters:
c- the character to check- Returns:
trueif the character is whitespace;falseotherwise
-
isXml
Returnstrueif the string is an XML document. The only requirement is that it contain either the xml start tag "<?xml" or the empty document tag "". - Parameters:
s- the string to check- Returns:
trueif the string is an XML document;falseotherwise
-