aspx page code.
<script type="text/javascript">
// Time validation for Scheduled Time
function ValidateScheduledTimeFormatSC() {
var msg = "";
var txtTimeValue = $("[id*='txtSchTime']").val();
regularExpression = /^(\d{1,2}):(\d{2})(:00)?(\s)?([AP]M|[ap]m)?$/;
try {
if (txtTimeValue != '') {
if (arrregularExpressions = txtTimeValue.match(regularExpression)) {
if (arrregularExpressions[4]) {
// check for am/pm. This is 12hours time format check
if (arrregularExpressions[1] < 1 || arrregularExpressions[1] > 12) {
msg = "Error: enter valid hours. Either 12hours with am/pm here am/pm is optional(or) 24hours time format: ";
}
}
else {
// This is 24hours time format check
if (arrregularExpressions[1] > 23) {
msg = "Error: enter valid hours. Either 12hours with am/pm (or) 24hours time format: ";
}
}
if (!msg && arrregularExpressions[2] > 59) {
msg = "Error: enter valid minutes: " + arrregularExpressions[2];
}
}
else {
msg = "Error: enter valid time format. Example: 10:15am or 19:20: ";
}
}
else {
$("#divSchTimeFormatError").css("display", "block");
}
if (msg != "" && txtTimeValue != "__:__ AM" && txtTimeValue != "__:__ PM") {
$("#divSchTimeFormatError").css("display", "block");
return false;
}
else {
if (msg != "") {
$("#divSchTimeFormatError").css("display", "none");
return true;
}
else {
$("#divSchTimeFormatError").css("display", "none");
return true;
}
}
}
catch (ex) { alert(ex); }
}
</script>
<div class="fieldset" runat="server" id="divScheduledTime">
<label>
<span id="span2" runat="server">Scheduled Time </span>
<asp:Label ID="lblSchTime" Visible="false" runat="server"></asp:Label>
</label>
<div id="divSchTimeFormatError" class="tooltip" style="margin-left: 410px;">
<span class="pointer"></span>Scheduled Time is not valid
</div>
<div class="margin_bottom_5">
<asp:TextBox ID="txtSchTime" runat="server" ClientIDMode="Static" class="inputTextTime"
onblur="ValidateScheduledTimeFormatSC();"></asp:TextBox>
<Ajax:MaskedEditExtender ID="MaskedSchTime" runat="server" AcceptAMPM="true" Mask="99:99"
AcceptNegative="None" Enabled="True" MaskType="Time" TargetControlID="txtSchTime" ClearTextOnInvalid="true" >
</Ajax:MaskedEditExtender>
</div>
</div>
<script type="text/javascript">
// Time validation for Scheduled Time
function ValidateScheduledTimeFormatSC() {
var msg = "";
var txtTimeValue = $("[id*='txtSchTime']").val();
regularExpression = /^(\d{1,2}):(\d{2})(:00)?(\s)?([AP]M|[ap]m)?$/;
try {
if (txtTimeValue != '') {
if (arrregularExpressions = txtTimeValue.match(regularExpression)) {
if (arrregularExpressions[4]) {
// check for am/pm. This is 12hours time format check
if (arrregularExpressions[1] < 1 || arrregularExpressions[1] > 12) {
msg = "Error: enter valid hours. Either 12hours with am/pm here am/pm is optional(or) 24hours time format: ";
}
}
else {
// This is 24hours time format check
if (arrregularExpressions[1] > 23) {
msg = "Error: enter valid hours. Either 12hours with am/pm (or) 24hours time format: ";
}
}
if (!msg && arrregularExpressions[2] > 59) {
msg = "Error: enter valid minutes: " + arrregularExpressions[2];
}
}
else {
msg = "Error: enter valid time format. Example: 10:15am or 19:20: ";
}
}
else {
$("#divSchTimeFormatError").css("display", "block");
}
if (msg != "" && txtTimeValue != "__:__ AM" && txtTimeValue != "__:__ PM") {
$("#divSchTimeFormatError").css("display", "block");
return false;
}
else {
if (msg != "") {
$("#divSchTimeFormatError").css("display", "none");
return true;
}
else {
$("#divSchTimeFormatError").css("display", "none");
return true;
}
}
}
catch (ex) { alert(ex); }
}
</script>
<div class="fieldset" runat="server" id="divScheduledTime">
<label>
<span id="span2" runat="server">Scheduled Time </span>
<asp:Label ID="lblSchTime" Visible="false" runat="server"></asp:Label>
</label>
<div id="divSchTimeFormatError" class="tooltip" style="margin-left: 410px;">
<span class="pointer"></span>Scheduled Time is not valid
</div>
<div class="margin_bottom_5">
<asp:TextBox ID="txtSchTime" runat="server" ClientIDMode="Static" class="inputTextTime"
onblur="ValidateScheduledTimeFormatSC();"></asp:TextBox>
<Ajax:MaskedEditExtender ID="MaskedSchTime" runat="server" AcceptAMPM="true" Mask="99:99"
AcceptNegative="None" Enabled="True" MaskType="Time" TargetControlID="txtSchTime" ClearTextOnInvalid="true" >
</Ajax:MaskedEditExtender>
</div>
</div>