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 boolean
equalsSorted
(boolean[] booleanArray1, boolean[] booleanArray2) Returnstrue
if the boolean arrays are equal.static boolean
equalsSorted
(byte[] byteArray1, byte[] byteArray2) Returnstrue
if the byte arrays are equal.static boolean
equalsSorted
(char[] charArray1, char[] charArray2) Returnstrue
if the char arrays are equal.static boolean
equalsSorted
(double[] doubleArray1, double[] doubleArray2) Returnstrue
if the double arrays are equal.static boolean
equalsSorted
(float[] floatArray1, float[] floatArray2) Returnstrue
if the float arrays are equal.static boolean
equalsSorted
(int[] intArray1, int[] intArray2) Returnstrue
if the int arrays are equal.static boolean
equalsSorted
(long[] longArray1, long[] longArray2) Returnstrue
if the long arrays are equal.static boolean
equalsSorted
(short[] shortArray1, short[] shortArray2) Returnstrue
if the short arrays are equal.static boolean
equalsSorted
(Object[] objArray1, Object[] objArray2) Returnstrue
if the object arrays are equal.static boolean
Returnstrue
if the string is an email address.static boolean
isAlphanumericName
(String name) Returnstrue
if the string is an alphanumeric name, meaning it contains nothing but English letters, numbers, and spaces.static boolean
isAscii
(char c) Returnstrue
if the character is in the ASCII character set.static boolean
static boolean
static boolean
isChar
(char c) Returnstrue
if the character is an upper or lower case English letter.static boolean
Returnstrue
if string consists only of upper and lower case English letters.static boolean
Returnstrue
if the string contains content.static boolean
isDate
(int month, int day, int year) Returnstrue
if the date is valid in the Gregorian calendar.static boolean
isDigit
(char c) Returnstrue
if the character is a digit between 0 and 9 (inclusive).static boolean
Returnstrue
if the string consists of only digits between 0 and 9 (inclusive).static boolean
Returnstrue
if the string is a valid domain name.static boolean
isEmailAddress
(String emailAddress) Returnstrue
if the string is a valid email address.static boolean
isEmailAddressSpecialChar
(char c) Returnstrue
if the character is a special character in an email address.static boolean
isFileExtension
(String fileExtension) Returnstrue
if the file extension is valid.static boolean
isFileName
(String name) static boolean
isFilePath
(String path, boolean parentDirAllowed) static boolean
isGregorianDate
(int month, int day, int year) Returnstrue
if the date is valid in the Gregorian calendar.static boolean
Returnstrue
if the string is a hexidecimal number.static boolean
isHostName
(String name) Returnstrue
if the string is a valid host name.static boolean
Returnstrue
if the string is an HTML document.static boolean
isIPAddress
(String ipAddress) Returnstrue
if the string is a valid IPv4 or IPv6 IP address.static boolean
isIPv4Address
(String ipAddress) Returnstrue
if the string is a valid IPv4 IP address.static boolean
isIPv6Address
(String ipAddress) Returnstrue
if the string is a valid IPv6 IP address.static boolean
isJulianDate
(int month, int day, int year) Returnstrue
if the date is valid in the Julian calendar.static boolean
Returnstrue
if the string contains a valid number according to the Luhn algorithm, commonly used to validate credit card numbers.static boolean
Returnstrue
if the string is a name, meaning it contains nothing but English letters and spaces.static boolean
Returnstrue
if the long number object is notnull
, meaning it is neither anull
reference or zero.static boolean
Returnstrue
if the object is notnull
, using the rules fromisNotNull(Long)
orisNotNull(String)
if the object is one of these types.static boolean
Returnstrue
if the string is notnull
, meaning it is not anull
reference, an empty string, whitespace, or the string "null
", with or without leading or trailing whitespace.static boolean
Returnstrue
if the long number object isnull
, meaning it is either anull
reference or zero.static boolean
Returnstrue
if the object isnull
, using the rules fromisNull(Long)
orisNull(String)
if the object is one of these types.static boolean
Returnstrue
if the string isnull
, meaning it is anull
reference, an empty string, whitespace, or the string "null
", with or without leading or trailing whitespace.static boolean
Returnstrue
if the string is a decimal integer number, meaning it contains nothing but decimal digits.static boolean
isPassword
(String password) Returnstrue
if the string is a valid password, meaning it is at least four characters long and contains only letters and decimal digits.static boolean
isPhoneNumber
(String phoneNumber) Returnstrue
if the string is a valid phone number.static boolean
static boolean
Returnstrue
if the string is a valid URL based on the rules inURL
.static boolean
Returnstrue
if the string is a valid URL based on the rules inURL
.static boolean
isVariableName
(String variableName) Returnstrue
if the string is a valid variable name in Java.static boolean
Returnstrue
if the string is a valid variable term, meaning it begins with "[$" and ends with "$]".static boolean
isWhitespace
(char c) Returnstrue
if the character is whitespace, meaning it is either thenull
character '0' or whitespace according toCharacter.isWhitespace(char)
.static boolean
Returnstrue
if the string is an XML document.
-
Constructor Details
-
Validator
public Validator()
-
-
Method Details
-
equalsSorted
public static boolean equalsSorted(boolean[] booleanArray1, boolean[] booleanArray2) Returnstrue
if the boolean arrays are equal.- Parameters:
booleanArray1
- the first boolean arraybooleanArray2
- the second boolean array- Returns:
true
if the booleans arrays are equal;false
otherwise
-
equalsSorted
public static boolean equalsSorted(byte[] byteArray1, byte[] byteArray2) Returnstrue
if the byte arrays are equal.- Parameters:
byteArray1
- the first byte arraybyteArray2
- the second byte array- Returns:
true
if the byte arrays are equal;false
otherwise
-
equalsSorted
public static boolean equalsSorted(char[] charArray1, char[] charArray2) Returnstrue
if the char arrays are equal.- Parameters:
charArray1
- the first char arraycharArray2
- the second char array- Returns:
true
if the char arrays are equal;false
otherwise
-
equalsSorted
public static boolean equalsSorted(double[] doubleArray1, double[] doubleArray2) Returnstrue
if the double arrays are equal.- Parameters:
doubleArray1
- the first double arraydoubleArray2
- the second double array- Returns:
true
if the double arrays are equal;false
otherwise
-
equalsSorted
public static boolean equalsSorted(float[] floatArray1, float[] floatArray2) Returnstrue
if the float arrays are equal.- Parameters:
floatArray1
- the first float arrayfloatArray2
- the second char array- Returns:
true
if the float arrays are equal;false
otherwise
-
equalsSorted
public static boolean equalsSorted(int[] intArray1, int[] intArray2) Returnstrue
if the int arrays are equal.- Parameters:
intArray1
- the first int arrayintArray2
- the second int array- Returns:
true
if the int arrays are equal;false
otherwise
-
equalsSorted
public static boolean equalsSorted(long[] longArray1, long[] longArray2) Returnstrue
if the long arrays are equal.- Parameters:
longArray1
- the first long arraylongArray2
- the second long array- Returns:
true
if the long arrays are equal;false
otherwise
-
equalsSorted
Returnstrue
if the object arrays are equal.- Parameters:
objArray1
- the first object arrayobjArray2
- the second object array- Returns:
true
if the object arrays are equal;false
otherwise
-
equalsSorted
public static boolean equalsSorted(short[] shortArray1, short[] shortArray2) Returnstrue
if the short arrays are equal.- Parameters:
shortArray1
- the first short arrayshortArray2
- the second short array- Returns:
true
if the short arrays are equal;false
otherwise
-
isAddress
Returnstrue
if 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:
true
if the string is an email address;false
otherwise
-
isAlphanumericName
Returnstrue
if the string is an alphanumeric name, meaning it contains nothing but English letters, numbers, and spaces.- Parameters:
name
- the string to check- Returns:
true
if the string is an Alphanumeric name;false
otherwise
-
isAscii
public static boolean isAscii(char c) Returnstrue
if 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:
true
if the character is in the ASCII character set;false
otherwise
-
isBlank
-
isBoolean
-
isChar
public static boolean isChar(char c) Returnstrue
if the character is an upper or lower case English letter.- Parameters:
c
- the character to check- Returns:
true
if the character is an upper or lower case English letter;false
otherwise
-
isChar
Returnstrue
if string consists only of upper and lower case English letters.- Parameters:
s
- the string to check- Returns:
true
if the string consists only of upper and lower case English letters
-
isContent
Returnstrue
if the string contains content. The only requirement is that it contain content that is not whitespace.- Parameters:
s
- the string to check- Returns:
true
if the string contains content;false
otherwise
-
isDate
public static boolean isDate(int month, int day, int year) Returnstrue
if the date is valid in the Gregorian calendar.- Parameters:
month
- the month to checkday
- the day to checkyear
- the year to check- Returns:
true
if the date is valid in the Gregorian calendar;false
otherwise
-
isDigit
public static boolean isDigit(char c) Returnstrue
if the character is a digit between 0 and 9 (inclusive).- Parameters:
c
- the character to check- Returns:
true
if the character is a digit between 0 and 9 (inclusive);false
otherwise
-
isDigit
Returnstrue
if the string consists of only digits between 0 and 9 (inclusive).- Parameters:
s
- the string to check- Returns:
true
if the string consists of only digits between 0 and 9 (inclusive);false
otherwise
-
isDomain
Returnstrue
if 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:
true
if the string is a valid domain name;false
otherwise
-
isEmailAddress
Returnstrue
if the string is a valid email address.- Parameters:
emailAddress
- the string to check- Returns:
true
if the string is a valid email address;false
otherwise
-
isEmailAddressSpecialChar
public static boolean isEmailAddressSpecialChar(char c) Returnstrue
if the character is a special character in an email address.- Parameters:
c
- the character to check- Returns:
true
if the character is a special character in an email address;false
otherwise
-
isFileExtension
Returnstrue
if the file extension is valid.- Parameters:
fileExtension
- string to check- Returns:
true
if the extension is valid;false
otherwise
-
isFileName
-
isFilePath
-
isGregorianDate
public static boolean isGregorianDate(int month, int day, int year) Returnstrue
if 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:
true
if the date is valid;false
otherwise
-
isHex
Returnstrue
if 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:
true
if the string is a hexidecimal number;false
otherwise- See Also:
-
isHostName
Returnstrue
if the string is a valid host name.- Parameters:
name
- the string to check- Returns:
true
if the string is a valid host name;false
otherwise
-
isHTML
Returnstrue
if 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:
true
if the string is an HTML document;false
otherwise
-
isIPAddress
Returnstrue
if the string is a valid IPv4 or IPv6 IP address.- Parameters:
ipAddress
- the string to check- Returns:
true
if the string is a valid IPv4 or IPv6 IP address;false
otherwise
-
isIPv4Address
Returnstrue
if the string is a valid IPv4 IP address.- Parameters:
ipAddress
- the string to check- Returns:
true
if the string is a valid IPv4 IP address;false
otherwise
-
isIPv6Address
Returnstrue
if the string is a valid IPv6 IP address.- Parameters:
ipAddress
- the string to check- Returns:
true
if the string is a valid IPv6 IP address;false
otherwise
-
isJulianDate
public static boolean isJulianDate(int month, int day, int year) Returnstrue
if 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:
true
if the date is valid in the Julian calendar;false
otherwise
-
isLUHN
Returnstrue
if 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:
true
if the string contains a valid number according to the Luhn algorithm;false
otherwise
-
isName
Returnstrue
if the string is a name, meaning it contains nothing but English letters and spaces.- Parameters:
name
- the string to check- Returns:
true
if the string is a name;false
otherwise
-
isNotNull
Returnstrue
if the long number object is notnull
, meaning it is neither anull
reference or zero.- Parameters:
l
- the long number object to check- Returns:
true
if the long number object is notnull
;false
otherwise
-
isNotNull
Returnstrue
if 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:
true
if the object is notnull
;false
otherwise
-
isNotNull
Returnstrue
if the string is notnull
, meaning it is not anull
reference, an empty string, whitespace, or the string "null
", with or without leading or trailing whitespace.- Parameters:
s
- the string to check- Returns:
true
if the string is notnull
;false
otherwise
-
isNull
Returnstrue
if the long number object isnull
, meaning it is either anull
reference or zero.- Parameters:
l
- the long number object to check- Returns:
true
if the long number object isnull
;false
otherwise
-
isNull
Returnstrue
if 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:
true
if the object isnull
;false
otherwise
-
isNull
Returnstrue
if the string isnull
, meaning it is anull
reference, an empty string, whitespace, or the string "null
", with or without leading or trailing whitespace.- Parameters:
s
- the string to check- Returns:
true
if the string isnull
;false
otherwise
-
isNumber
Returnstrue
if the string is a decimal integer number, meaning it contains nothing but decimal digits.- Parameters:
number
- the string to check- Returns:
true
if the string is a decimal integer number;false
otherwise
-
isPassword
Returnstrue
if 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:
true
if the string is a valid password;false
otherwise
-
isPhoneNumber
Returnstrue
if 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:
true
if the string is a valid phone number;false
otherwise
-
isUri
-
isUrl
Returnstrue
if the string is a valid URL based on the rules inURL
.- Parameters:
url
- the string to check- Returns:
true
if the string is a valid URL;false
otherwise
-
isUrl
Returnstrue
if 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:
true
if the string is a valid URL;false
otherwise
-
isVariableName
Returnstrue
if the string is a valid variable name in Java.- Parameters:
variableName
- the string to check- Returns:
true
if the string is a valid variable name in Java;false
otherwise
-
isVariableTerm
Returnstrue
if the string is a valid variable term, meaning it begins with "[$" and ends with "$]".- Parameters:
s
- the string to check- Returns:
true
if the string is a valid variable term;false
otherwise
-
isWhitespace
public static boolean isWhitespace(char c) Returnstrue
if the character is whitespace, meaning it is either thenull
character '0' or whitespace according toCharacter.isWhitespace(char)
.- Parameters:
c
- the character to check- Returns:
true
if the character is whitespace;false
otherwise
-
isXml
Returnstrue
if 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:
true
if the string is an XML document;false
otherwise
-