473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Textbox to dislplay Time (23:59) or empty string

Hi!

I want the user to edit a textbox which allows following values only:
- Time (Format: 23:59, HH:MM)
or
- NULL (empty string)
What can I do, so that this works kinda automatically, meaning on the
client side. It would be also nice, that not only errors would be
detected, but also that "wanted error" would be corrected if possible,
e.g. exchange "30" by "00:30".

Which control and properties do I need? As a reminder, I do not use a
bound field but a TextBox.

Thanks

Joe
May 2 '07 #1
8 4754
Hi!
>
I want the user to edit a textbox which allows following values only:
- Time (Format: 23:59, HH:MM)
or
- NULL (empty string)
What can I do, so that this works kinda automatically, meaning on the
client side. It would be also nice, that not only errors would be
detected, but also that "wanted error" would be corrected if possible,
e.g. exchange "30" by "00:30".
Which control and properties do I need? As a reminder, I do not use a
bound field but a TextBox.

Thanks

Joe
You can add a RegularExpressionValidator.
Have the ControlToValidate property point to your textbox
and set the ValidationExpression to [0-2]?[0-9]:[0-5][0-9]
Set the ErrorMessage to the message you want to display if an error
is made.

This will validate that it looks like a correct time, or that nothing
is entered.

Note: the code that want this value (tries to store it?) should check
Page.Isvalid before using it.

Hans Kesting
May 2 '07 #2
"Joe Kovac" <Jo****@nospam.comwrote in message
news:72***************************@news.inode.at.. .
Hi!

I want the user to edit a textbox which allows following values only:
- Time (Format: 23:59, HH:MM)
or
- NULL (empty string)
What can I do, so that this works kinda automatically, meaning on the
client side. It would be also nice, that not only errors would be
detected, but also that "wanted error" would be corrected if possible,
e.g. exchange "30" by "00:30".

Which control and properties do I need? As a reminder, I do not use a
bound field but a TextBox.
I have a JavaScript function for this:

function isTime(pstrTime)
{
var strValidChars = "0123456789:";
var strChar;

if (pstrTime.length != 5) return false;

for (intChar = 0; intChar < pstrTime.length; intChar++)
{
strChar = pstrTime.charAt(intChar);
if (strValidChars.indexOf(strChar) == -1)
{
return false;
}
}

if (parseInt(pstrTime.substring(0, 2)) 23) return false;
if (pstrTime.substring(2, 3) != ":") return false;
if (parseInt(pstrTime.substring(3)) 59) return false;

return true;
}
--
http://www.markrae.net

May 2 '07 #3
"Hans Kesting" <ne***********@spamgourmet.comwrote in message
news:c0*************************@news.microsoft.co m...
You can add a RegularExpressionValidator.
Have the ControlToValidate property point to your textbox
and set the ValidationExpression to [0-2]?[0-9]:[0-5][0-9]
Set the ErrorMessage to the message you want to display if an error
is made.

This will validate that it looks like a correct time, or that nothing
is entered.
Unless I'm very much mistaken, this would consider 29:59 as valid, wouldn't
it...?
--
http://www.markrae.net

May 2 '07 #4
Mark Rae wrote:
"Joe Kovac" <Jo****@nospam.comwrote in message
news:72***************************@news.inode.at.. .
>Hi!

I want the user to edit a textbox which allows following values only:
- Time (Format: 23:59, HH:MM)
or
- NULL (empty string)
What can I do, so that this works kinda automatically, meaning on the
client side. It would be also nice, that not only errors would be
detected, but also that "wanted error" would be corrected if possible,
e.g. exchange "30" by "00:30".

Which control and properties do I need? As a reminder, I do not use a
bound field but a TextBox.

I have a JavaScript function for this:

function isTime(pstrTime)
{
var strValidChars = "0123456789:";
var strChar;

if (pstrTime.length != 5) return false;

for (intChar = 0; intChar < pstrTime.length; intChar++)
{
strChar = pstrTime.charAt(intChar);
if (strValidChars.indexOf(strChar) == -1)
{
return false;
}
}

if (parseInt(pstrTime.substring(0, 2)) 23) return false;
if (pstrTime.substring(2, 3) != ":") return false;
if (parseInt(pstrTime.substring(3)) 59) return false;

return true;
}
I will give this function a try and moreover I will try to include the
auto complete that makes 00:30 out of 30.

Thanks to all of you so far.
May 2 '07 #5
"Joe Kovac" <Jo****@nospam.comwrote in message
news:61*************************@news.inode.at...
I will give this function a try and moreover I will try to include the
auto complete that makes 00:30 out of 30.
I would strongly advise against that sort of 'masked edit' functionality in
ASP.NET, especially if you're intending to wire it up to one of the
keystroke events of the TextBox...

I always have a single routine which validates the entire page rather than
individual control validation.

However, if you absolutely must do autocomplete, consider doing it in the
onblur() event...
--
http://www.markrae.net

May 2 '07 #6
Mark Rae wrote:
"Joe Kovac" <Jo****@nospam.comwrote in message
news:61*************************@news.inode.at...
>I will give this function a try and moreover I will try to include the
auto complete that makes 00:30 out of 30.

I would strongly advise against that sort of 'masked edit' functionality
in ASP.NET, especially if you're intending to wire it up to one of the
keystroke events of the TextBox...
What exactly speaks against a (hopefully) comfortable auto completion?
(I currently think about performance, browser incompatibility, etc.)
I always have a single routine which validates the entire page rather
than individual control validation.

However, if you absolutely must do autocomplete, consider doing it in
the onblur() event...
How about onchange()?
May 2 '07 #7
"Joe Kovac" <Jo****@nospam.comwrote in message
news:54**************************@news.inode.at...
What exactly speaks against a (hopefully) comfortable auto completion? (I
currently think about performance, browser incompatibility, etc.)
Both of those... If you absolutely must roll your own autocomplete, you must
make absolutely sure that you switch the in-built autocomplete off for IE /
Opera 9:
http://www.google.co.uk/search?sourc...2+autocomplete
>I always have a single routine which validates the entire page rather
than individual control validation.

However, if you absolutely must do autocomplete, consider doing it in the
onblur() event...

How about onchange()?
onchange can be really irritating:
http://www.velocityreviews.com/forum...ttextquot.html
--
http://www.markrae.net

May 2 '07 #8
"Hans Kesting" <ne***********@spamgourmet.comwrote in message
news:c0*************************@news.microsoft.co m...
>You can add a RegularExpressionValidator.
Have the ControlToValidate property point to your textbox
and set the ValidationExpression to [0-2]?[0-9]:[0-5][0-9]
Set the ErrorMessage to the message you want to display if an error
is made.
This will validate that it looks like a correct time, or that nothing
is entered.
Unless I'm very much mistaken, this would consider 29:59 as valid,
wouldn't it...?
You are right.
I *knew* I had forgotten to check for those special situations :-(

(([01]?[0-9])|2[0-3]):[0-5][0-9]
Hans Kesting
May 3 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tetet B via .NET 247 | last post by:
I'm using VB.Net and trying to retrieve the data in the textboxcell of a datagrid after a successful display (used Databind).User can either display data or enter data in the textbox. I canalways get...
8
by: Gidi | last post by:
hello, i have a textbox that represnts a date and i want to pare it to a DateTime, but sometimes this textBox can be empty string and i want to send it to the DataBase as null or as empty Date, how...
5
by: VMI | last post by:
How can I validate a null string or an empty string in the same IF statement? If I use this: if (myString.Trim().Length <= 0 || myString == null) { //do stuff } I'll get a run-time error...
11
by: Dan Bass | last post by:
which one do you use and why? MyString == null || MyString == "" vs MyString == null || MyString.Length == 0
21
by: M D | last post by:
You know how you assume you know until you find out you don't know. Well, I typed into a function definition "..., new String("")). I know what I want. Everyone reading this knows what I want....
26
by: Neville Lang | last post by:
Hi all, I am having a memory blank at the moment. I have been writing in C# for a number of years and now need to do something in VB.NET, so forgive me such a primitive question. In C#, I...
6
by: mesut | last post by:
Hi colleagues, I have a small issue. I don't know how to solve it. I'm caching a property value : True or False. I do this manually and it works. But I would like to remove the cache if the the...
18
by: Academia | last post by:
I let the use modify the text of a combobox and then I replace the selected item with the new text (in Keyup event). But if he sets the Text property to an empty string ("") that sets the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.