|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Regular expressions problem
i have a vb.net application that accepts time from a textbox. problem is i need to use a RegularExpressionValidator to validate it. can anyone please give me the regex to use in the regular expression editor for this time format, '9:00' or '10:00'. thanks in advance.
|
|
#2
|
||||
|
||||
|
Quote:
Code:
\d{1,2}[:]\d{2}
__________________
mr... mike.rusaw@realpage.com RalPage, Inc. "I have made this letter longer than usual, only because I have not had the time to make it shorter." - Blaise Paschal |
|
#3
|
|||
|
|||
|
didnt work dude. also the first character can either be a whitespace or 1. thanks.
|
|
#4
|
||||
|
||||
|
Quote:
try this: Code:
^\d{1,2}[:]\d{2}$
|
|
#5
|
|||
|
|||
|
Quote:
yup thats what i did |
|
#6
|
|||
|
|||
|
Quote:
First of all, that's an insubordinate regular expression. You're not going to catch 38:93 with that. I conjured up an expression that I think will suit your needs: ^[1][0-2]|^[1-9]{1}:[0-5]\d$ What this does is checks the digits preceding the colon. If it's a two digit set, then it checks to ensure that it starts with a 1, followed by either 0, 1 or 2. Otherwise, it's evaluated as a numerical value that must have a value with an upper bound of 9 and lower bound of 1. Then the semicolon is evaluated and the number following the semicolon is checked to ensure that it falls in a range with an upper bound of 5 and lower bound of 0. The number after that can be any numerical value (0-9). If any of the evaluations fail, the expression is invalid. 12:48 matches, but 12:69 doesn't. 4:45 matches but 0:45 doesn't. etc.. If you want to check military time, you can make changes based on what I just explained. Secondly, does the following code work for you? Code:
<form runat="server">
<asp:textbox id="textbox1" runat="server" />
<asp:button id="button1" runat="server" text="submit" causesValidation="true" />
<asp:RegularExpressionValidator controlToValidate="textbox1" validationExpression="^[1][0-2]|^[1-9]{1}:[0-5]\d$" runat="server" display="dynamic" text="Invalid expression" />
</form>
|
|
#7
|
|||
|
|||
|
[QUOTE=sano]First of all, that's an insubordinate regular expression. You're not going to catch 38:93 with that.
I conjured up an expression that I think will suit your needs: ^[1][0-2]|^[1-9]{1}:[0-5]\d$ What this does is checks the digits preceding the colon. If it's a two digit set, then it checks to ensure that it starts with a 1, followed by either 0, 1 or 2. Otherwise, it's evaluated as a numerical value that must have a value with an upper bound of 9 and lower bound of 1. Then the semicolon is evaluated and the number following the semicolon is checked to ensure that it falls in a range with an upper bound of 5 and lower bound of 0. The number after that can be any numerical value (0-9). If any of the evaluations fail, the expression is invalid. 12:48 matches, but 12:69 doesn't. 4:45 matches but 0:45 doesn't. etc.. thanks dude that code worked but one more thing though, how do i get it to accpet a whitespace at the beginning if it's lets say 9:00 AM? |
|
#8
|
|||
|
|||
|
let me make that clear. lets say the time-in is 9:00, i want it to accept a whitespace before the 9.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > .Net Development > Regular expressions problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|