Use the following regular expression:
^\d{4}-\d{2}-\d{2}$
as in
if (str.matches("\\d{4}-\\d{2}-\\d{2}")) {
...
}
With the matches
method, the anchors ^
and $
(beginning and end of string, respectively) are present implicitly.
More Related Contents:
- Remove HTML tags from a String
- Date object SimpleDateFormat not parsing timestamp string correctly in Java (Android) environment
- java parsing string to date
- Make SimpleDateFormat.parse() fail on invalid dates (e.g. month is greater than 12)
- Generic support for ISO 8601 format in Java 6
- SimpleDateFormat.parse() ignores the number of characters in pattern
- Parse String date in (yyyy-MM-dd) format
- Why can’t this SimpleDateFormat parse this date string?
- Find all words with 3 letters with regex
- Regex date validation for yyyy-mm-dd [duplicate]
- Determine if a String is a valid date before parsing
- Fastest way to parse a date in Basic ISO 8601 format, using Java [closed]
- How to get the day from timezone in java [duplicate]
- Java: splitting a comma-separated string but ignoring commas in quotes
- How to read XML using XPath in Java
- “Expected BEGIN_OBJECT but was STRING at line 1 column 1”
- Dates with no time or timezone component in Java/MySQL
- Split string with dot as delimiter
- Java how to replace 2 or more spaces with single space in string and delete leading and trailing spaces
- Java, Calculate the number of days between two dates [duplicate]
- Get the index of a pattern in a string using regex
- How to decode JSON with unknown field using Gson?
- Regular expression for excluding special characters [closed]
- Spring Boot Jackson date and timestamp Format
- Comparing date strings in Java [duplicate]
- Why does Java’s Date.getYear() return 111 instead of 2011?
- Regex: ?: notation (Question mark and colon notation) [duplicate]
- Reading HTML file to DOM tree using Java
- Regex for checking if a string is strictly alphanumeric
- Why is subtracting these two epoch-milli Times (in year 1927) giving a strange result?