public class JSONValidation extends Object
isLeapYear(int) and monthLength(int, int) functions; these are required for date
checking and it costs nothing to make them available for general use.| Constructor and Description |
|---|
JSONValidation() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
isDate(String string)
Test for conformity to the
date format type. |
static boolean |
isDateTime(String string)
Test for conformity to the
date-time format type. |
static boolean |
isDuration(String string)
Test for conformity to the
duration format type. |
static boolean |
isEmail(String string)
Test for conformity to the
email format type. |
static boolean |
isHostname(String string)
Test for conformity to the
hostname format type. |
static boolean |
isIPV4(String string)
Test for conformity to the
ipv4 format type. |
static boolean |
isIPV6(String string)
Test for conformity to the
ipv6 format type. |
static boolean |
isJSONPointer(String string)
Test for conformity to the
json-pointer format type. |
static boolean |
isLeapYear(int year)
Determine whether a given year is a leap year (only meaningful for years covered by the Gregorian calendar).
|
static boolean |
isRegex(String string)
Test for conformity to the
regex format type. |
static boolean |
isRelativeJSONPointer(String string)
Test for conformity to the
relative-json-pointer format type. |
static boolean |
isTime(String string)
Test for conformity to the
time format type. |
static boolean |
isURI(String string)
Test for conformity to the
uri format type. |
static boolean |
isURIReference(String string)
Test for conformity to the
uri-reference format type. |
static boolean |
isUUID(String string)
Test for conformity to the
uuid format type. |
static int |
monthLength(int year,
int month)
Calculate the length of a given month (only meaningful for years covered by the Gregorian calendar).
|
public static boolean isLeapYear(int year)
year - the yeartrue if the year is a leap yearpublic static int monthLength(int year,
int month)
year - the yearmonth - the month (must be in the range 1 to 12)IllegalArgumentException - if the month is not in the range 1 to 12public static boolean isDateTime(String string)
date-time format type. A string is valid if it conforms to the "date-time"
production in RFC 3339, section 5.6.string - the string to be testedtrue if the string is correctpublic static boolean isDate(String string)
date format type. A string is valid if it conforms to the "full-date"
production in RFC 3339, section 5.6.string - the string to be testedtrue if the string is correctpublic static boolean isTime(String string)
time format type. A string is valid if it conforms to the "full-time"
production in RFC 3339, section 5.6.string - the string to be testedtrue if the string is correctpublic static boolean isDuration(String string)
duration format type. A string is valid if it conforms to the "duration"
production in RFC 3339, Appendix A.string - the string to be testedtrue if the string is correctpublic static boolean isURI(String string)
uri format type. A string is valid if it conforms to
RFC 3986.string - the string to be testedtrue if the string is correctpublic static boolean isURIReference(String string)
uri-reference format type. A string is valid if it conforms to
RFC 3986 (either a URI or a relative-reference).string - the string to be testedtrue if the string is correctpublic static boolean isUUID(String string)
uuid format type. A string is valid if it conforms to
RFC 4122.string - the string to be testedtrue if the string is correctpublic static boolean isHostname(String string)
hostname format type. A string is valid if it conforms to
RFC 1123, section 2.1.string - the string to be testedtrue if the string is correctpublic static boolean isEmail(String string)
email format type.
Validation of email addresses is difficult, largely because the specification in RFC 5322 makes reference to earlier "obsolete" forms of email addresses that are expected to be accepted as valid. This function does not attempt to cover the entire range of obsolete addresses; instead, it implements a form of validation derived from the regular expression at the web site emailregex.com for the "local-part" (the addressee or mailbox name), and it uses the hostname validation from RFC 1123 for the "domain".
string - the string to be testedtrue if the string is correctpublic static boolean isIPV4(String string)
ipv4 format type. A string is valid if it conforms to
RFC 2673, section 3.2.string - the string to be testedtrue if the string is correctpublic static boolean isIPV6(String string)
ipv6 format type. A string is valid if it conforms to
RFC 4291, section 2.2.
NOTE: The
JSON Schema Validation
specification says (§ 7.3.4) that a string conforming to the ipv6 format must be an "IPv6 address
as defined in RFC 4291, section 2.2". Subsequent to RFC 4291,
RFC 5952 recommended stricter restrictions on the
representation of IPV6 addresses, including mandating the use of lower case for all alpha characters, and
prohibiting the use of "::" to compress a single zero 16-bit field. Because the JSON Schema Validation
specification refers only to RFC 4291, not RFC 5952, this function does not implement the stricter restrictions
of the later document.
string - the string to be testedtrue if the string is correctpublic static boolean isJSONPointer(String string)
json-pointer format type. A string is valid if it conforms to
RFC 6901, section 5.string - the string to be testedtrue if the string is correctpublic static boolean isRelativeJSONPointer(String string)
relative-json-pointer format type. A string is valid if it conforms to
Relative JSON Pointers.string - the string to be testedtrue if the string is correctpublic static boolean isRegex(String string)
regex format type. A string is valid if it conforms to
ECMA 262 regular expression dialect.
Since the Java Pattern class used here implements a dialect very close to, but not identical to the
ECMA 262 variant, it is possible that in rare cases there may be subtle inconsistencies in the results of this
function.string - the string to be testedtrue if the string is correctCopyright © 2022. All rights reserved.