.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 12th, 2004, 02:54 PM
jpreyes jpreyes is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 9 jpreyes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old March 12th, 2004, 04:47 PM
mrusaw's Avatar
mrusaw mrusaw is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Dallas, Texas
Posts: 138 mrusaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to mrusaw Send a message via Yahoo to mrusaw
Quote:
Originally Posted by jpreyes
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.


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

Reply With Quote
  #3  
Old March 12th, 2004, 05:01 PM
jpreyes jpreyes is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 9 jpreyes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
didnt work dude. also the first character can either be a whitespace or 1. thanks.

Reply With Quote
  #4  
Old March 12th, 2004, 05:06 PM
mrusaw's Avatar
mrusaw mrusaw is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Dallas, Texas
Posts: 138 mrusaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to mrusaw Send a message via Yahoo to mrusaw
Quote:
Originally Posted by jpreyes
didnt work dude. also the first character can either be a whitespace or 1. thanks.


try this:

Code:
^\d{1,2}[:]\d{2}$

Reply With Quote
  #5  
Old March 12th, 2004, 05:29 PM
jpreyes jpreyes is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 9 jpreyes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by mrusaw
try this:

Code:
^\d{1,2}[:]\d{2}$



yup thats what i did

Reply With Quote
  #6  
Old March 13th, 2004, 01:38 AM
sano sano is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Location: Redmond, WA
Posts: 218 sano User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Quote:
Originally Posted by jpreyes
yup thats what i did


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>

Reply With Quote
  #7  
Old March 15th, 2004, 10:54 AM
jpreyes jpreyes is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 9 jpreyes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
[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?

Reply With Quote
  #8  
Old March 15th, 2004, 11:16 AM
jpreyes jpreyes is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 9 jpreyes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
let me make that clear. lets say the time-in is 9:00, i want it to accept a whitespace before the 9.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > Regular expressions problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT