I need a regular expression for valid time zone, tried the following one.
But I'm not sure about it.
Please help me to find out anything wrong in the following regular expression.
Here colon and minutes are optional. how can i change it to mandatory.
If there is no minutes user should input 00 (+05:00).
Please help me to solve this issue.
var chkzone = "+05:30"
if(chkzone .match(/^(Z|[+-](?:2[0-3]|[01]?[0-9])(?::?(?:[0-5]?[0-9]))?)$/))
{
alert('works out');
}
else
{
alert("Time zone wrong")
}
Create a regular expression to check time in 24-hour format as mentioned below: ( represents the start of the group. [01]? [0-9] represents the time starts with 0-9, 1-9, 00-09, 10-19. | represents or. 2 [0-3] represents the time starts with 20-23. ) represents the end of the group. : represents the time should be followed by a colon (:).
A regular expression to match a Julian date in the format YYDDD. /^ ( [0-9] {2}) (00 [1-9]|0 [1-9] [0-9]| [1-2] [0-9] [0-9]|3 [0-5] [0-9]|36 [0-6])$/ A regular expression to match a valid date in the format YYYY-MM-DD. Date, Month, Leap Year validation is included.
A regular expression for month that can be used to validate month input. A Regular Expression to match and validate Credit Card Expiration Date in MM/YY format. A regular expression to match an EU date format: DD-MM-YYYY.
“1:00”, “2:00”, “13:01”, 3. “23:59″,”15:00” 4. “00:00″,”0:00” Time format doesn’t match: 1. “24:00” – hour is out of range [0-23] 2. “12:60” – minute is out of range [00-59] 3. “0:0” – invalid format for minute, at least 2 digits 4. “13:1” – invalid format for minute, at least 2 digits 5. “101:00” – hour is out of range [0-23]
The following regex matches timezones with mandatory double digit hours/minutes, or the letter Z
:
/^(?:Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])$/
Explanation:
^ # Start of string
(?: # Match the following non-capturing group:
Z # Either a literal Z
| # or
[+-] # a plus or minus sign
(?: # followed by this non-capturing group:
2[0-3] # Either a number between 20 and 23
| # or
[01][0-9] # a number between 00 and 19
) # End of inner non-capturing group
: # Match a literal colon
[0-5][0-9] # Match a number between 00 and 59
) # End of outer non-capturing group
$ # End of string
See it live on regex101.com.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With