Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Sujitha
Time validation
1 Answer(s)      2 years and 2 months ago
Posted in : JavaScript Questions


Hi. I have a text box in html to get time in the format of hour:minutes. I have to validate that the given information in that text box is in the correct format or not using java script. Please help me for doing project.


Advertisement
View Answers

August 13, 2012 at 12:48 PM


Here is a code that accepts the time in the format hh:mm. If the user enters the time in wrong format, it displays the error message.

<html>
<script language="JavaScript">
 function check(timeStr) {
 var regex = /^(\d{1,2}):(\d{2})?$/;
 var timArr = timeStr.match(regex);
 if (timArr == null) {
 alert("Time is not in a valid format.");
 document.frm.timetext.value="";
 return false;
 }
hour = timArr[1];
minute = timArr[2];
if (hour < 0  || hour > 23) {
alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
document.frm.timetext.value="";
return false;
}
if (minute<0 || minute > 59) {
alert ("Minute must be between 0 and 59.");
document.frm.timetext.value="";
return false;
}
return false;
}
</script>
<form name="frm">
      Time (HH:MM)
      <input type="text" name="timetext">
      <input type="button" value="Check" onclick="return check(document.frm.timetext.value);">
      </form>
</html>


Related Tutorials/Questions & Answers:
Time validation
Time validation  Hi. I have a text box in html to get time... project.   Here is a code that accepts the time in the format hh:mm. If the user enters the time in wrong format, it displays the error message. <
validation
validation  validation
Advertisements
validation
validation  we are doing payroll system project in java.So pls provide the complete validation code for employee master form
validation.....
validation.....  hi.......... thanks for ur reply for validation code. but i want a very simple code in java swings where user is allowed to enter only numerical values in textbox , if he enters string values then it should
validation
Validation method valid the in put. otherwise call the javascript onsubmit to check... code.Ok if you use struts then you can use Validation method valid the in put
Validation
); JLabel label=new JLabel("JTable validation Example",JLabel.CENTER); JPanel panel=new JPanel(); panel.add(scroll); JFrame frame=new JFrame("JTable validation
validation
validation  please help me to check validation for <form> <table class="form"> <tr> <td class="col1"> <label>Sno:</label> </td> <td
Struts Login Validation. In This code setter of login page is called only one time again it doesnt call it. Why..?
Struts Login Validation. In This code setter of login page is called only one time again it doesnt call it. Why..?  **struts.xml** <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software
time
time  how to find the current system time between the user login and logout using java
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  sir, i want to show system time on a textfield in awt(java). woulk you send me an example of time which can show time in standard format like H:M:S pls help me sir   Display time in JTextField import
time
time format hh:mm:ss  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do?   Here is a jsp example that fetch the time from the database and display
time
time display only as hh:mm.  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do?   Here is a jsp example that fetch the time from the database
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do?   Here is a jsp example that fetch the time from the database and display in different
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do?   Here is a jsp example that fetch the time from the database and display in different
time
retrieved time from mysql database  Hi. I have retrieved time from.... wat to do?   Here is a jsp example that fetch the time from... is a jsp example that fetch the time from the database and display in different
validation files
validation files  If I place validation files in the folder where the action classes are present,will there any error arise
javascript validation
javascript validation  validation of comparing dropdownlist and textbox in javascript
NSURL Validation
NSURL Validation  How to validate a NSURL string using special character validation
form validation
form validation  how the form validation is done in jsf form using javaScript
validation query
validation query  where I should kept properties file inside struts Web application
Validation - Struts
Validation  what is the best way to use validation in Struts?either "validation.xml" or JavaScript
Validation of datepicker
Validation of datepicker  I have a datepicker in my JSp...the seleted dates are put in a text box. I want the alert the user from selecting future... a future date is entered..How to do this validation in javascript or jsp
email validation
email validation  during email validation.... after domain name which it means if example example@gmail.co .... this address allowed by any validation program .... but i want to show invalid email address because domain name com
 

 

 

DMCA.com