I am trying to validate time zone offset which has the format of optional minus sign, followed by two digits, followed by colon followed by two more digits; like -05:00 or 04:30. I used \\b[-]?\\d{2}:\\d{2}\\b as validation expression, tested it on some online RE testing sites and I get "Successful Match" but validator keeps returning falase. I can't see what I am doing wrong. I enter -05:00 or -13:99 and they both return false. I tried to escape the colon but same thing.
Drop the word boundaries then you'll get your matches.
-?\d{2}:\d{2}
If you only want the first occurrence then make it like this:
-?\d{2}:\d{2}$
If you only want to match valid times use this one:
-?([0-2][0-3]|[0-1][0-9]):([0-5][0-9])
The above one matches any hour in the range of 0-23:0-59 btw.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.