i.split(/[:\\]/);
Main Topics
Browse All TopicsI have an Automatic Time format function that puts a colon in automatically. My problem is, I need to allow a backspace of the colon. Any Ideas? thank you much.
function CheckTime(TxtObj)
{
var i = TxtObj.value;
var n = parseInt(i);
var o = TxtObj.value;
if(i.length<=2)
{
if(n>=3 && n<=9){o='0'+n+':';}
if(n>=24 && n<=25){o='02:'+(n-20);}
if(n>=26 && n<=29){o='02:';}
if(n>=10){o=i+':';}
}
if(i.length>=4)
{
var h = i.split(':')[0];
var m = i.split(':')[1];
if(m.length==1&&m>=6){o=h+
}
TxtObj.value = o;
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The reason you are having trouble is that the routine is being invoked onkeyup.
For example, say the current value is "1" and we type "2". This routine changes the value to "12:". So, when we press the backspace, the ":" is deleted, and then immediately appended.
So, we need to have the routine know what kind of key was pressed. For a digit, we can execute the code above. For a tab, or alt-tab, we can validate the time, for an enter, we can validate the time, and for a backspace, we remove the last character.
Does that make sense?
few flaws i see....
if the input is 24 say it will remain as 24 why?
if ( i.length <= 2 ) {
if ( n >= 3 && n <= 9 ) { o = '0' + n + ':'; }
if ( n >= 24 && n <= 25 ) { o = '02:' + ( n - 20 ); }// This is the condition it will satisfy! so it will be 02:4
if ( n >= 26 && n <= 29 ) { o = '02:'; }
if ( n >= 10 ) { o = i + ':'; }// but this will again satisfy so the result will be 24:
// for any number >=10 same thing will apply
}
next applying HonorGod's solution
you enter 12, it will get entered as 12:...
you hit a backspace it will be 12
next you enter 3 and then 4 it will be 1234, remember there is no semi colon
if ( i.length >= 4 ) {
var h = i.split(':')[0];
var m = i.split(':')[1];// you will probably encounter the error here...
if ( m.length == 1 && m >=6 ) { o = h + ':' }
}
so you need to refine the logic
Business Accounts
Answer for Membership
by: waf771Posted on 2009-10-30 at 17:30:22ID: 25707739
Oh, I forgot to mention, I am calling this function with the OnKeyUp attribute