Jump to content
New Reality: Ads For Members ×

Input validate


Xster

Recommended Posts

Can someone pls tell me how to fix this codes somekind like if user didnt insert anything to the text box,

it pop-ups an prompt error like "Pls insert bla bla bla" and how to create time format validation in JavaScript? any answers would help..

TQ in advance!

 

<html>
<head>
<title><?php echo $row_rs1['title']; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../pnec.css" rel="stylesheet" type="text/css">
<script type="text/javascript"> // this section im very confuse
function checkForm()
{
var timeFrom, timeFrom1, timeTo, timeTo1;
    with(window.document.msgform)		
{
        ctime1 = timeFrom;
        ctime2 = timeFrom1;
        ctime3 = timeTo;
        ctime4 = timeTo1;
}
if(trim(ctime1.value) == '')
    {
        alert('Please enter your time from');
        ctime1.focus();
        return false;
    }
    else if(trim(ctime2.value) == '')
    {
        alert('Please enter your time from');
        ctime2.focus();
        return false;
    }
    else if(trim(ctime3.value) == '')
    {
        alert('Please enter your time to');
        ctime3.focus();
        return false;
    }
    else if(trim(ctime4.value) == '')
    {
        alert('Please enter your time to');
        ctime4.focus();
        return false;
    }
    else
    {
        ctime1.value = trim(ctime1.value);
        ctime2.value = trim(ctime2.value);
        ctime3.value = trim(ctime3.value);
        ctime4.value = trim(ctime4.value);
        return true;
    }
}		
</script>
</head>
Welcome, <?php echo "".$_SESSION['username'];?>!</td>
              <?php 
			if(!isset($_POST['submit']))
			{
			?>
            <form action="" method="post" onSubmit="return (checkForm();">
              <table width="98%" height="301" border="0" cellpadding="10" cellspacing="0" bordercolor="#FFFFFF">
                <!--Step 3 : Select Time-->
                <tr>
                  <td style="border-width:1px; border-color:#A8B2C6; border-style:solid;" class="body" colspan="2">
                    <tr>
                  <td width="15%" class="body-facilities">From:</td>
                  <td class="body-facilities"> 
                      <input type="text" name="timeFrom" size="1" maxlength="2">
 : 
                    <input type="text" name="timeFrom1" size="1" maxlength="2">
 <sup style="color:#FF0000">eg: 08:00</sup> </td>
                </tr>
                <tr>
                  <td class="body-facilities">To:</td>
                  <td class="body-facilities"> 
                      <input type="text" name="timeTo" size="1" maxlength="2">
 : 
                    <input type="text" name="timeTo1" size="1" maxlength="2">
 <sup style="color:#FF0000">eg: 23:00</sup></td>
                </tr>
                <tr>
                  <td colspan="2" align="right"><input type="submit" name="submit" value="Next" onClick="checkForm();">
  
                    <input type="reset" name="reset" value="Reset">
  
                    <input type="hidden" name="fac_id" value="<?php echo $fac_id;?>">
                  </td>
                </tr>
              </table>
            </form>
            <?php
			}
			?>
          </td>
        </tr>
    </table>

 

Link to comment
https://forums.phpfreaks.com/topic/40300-input-validate/
Share on other sites

I do some modified and Its runs well.

but I need another validations that only accept user to fill in the input box like if the day (Monday to Friday) the actual operating hours is 10:00 to 22:00 and (Saturday and Sunday) is 09:00 to 23:00..give me some idea how to figure this pls..TQ~

 

This is JavaScript Function

function formvalidations(){
var FHour = document.getElementById("timeFrom");
var FMin  = document.getElementById("timeFrom1");
var THour = document.getElementById("timeTo");
var TMin = document.getElementById("timeTo1");

if(checkHour(FHour, "Invalid Data Entry in the From Hour selection")){
	if(checkMin(FMin, "Invalid Data Entry in the From Minute selection")){
		if(checkHour(THour, "Invalid Data Entry in the To Hour selection")){
			if(checkMin(TMin, "Invalid Data Entry in the To Minute selection")){
				return true;
			}
		}
	}
}
return false;
}

function checkHour(elem, helperMsg){
var numericExpression = /^[0-9]+$/;

if(elem.value.match(numericExpression)){
	if(elem.value >= 08 && elem.value <= 22){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}else{
	alert(helperMsg);
	elem.focus();
	return false;
}
}

function checkMin(elem, helperMsg){
var numericExpression = /^[0-9]+$/;

if(elem.value.match(numericExpression)){
	if(elem.value >= 0 && elem.value <= 59){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}else{
	alert(helperMsg);
	elem.focus();
	return false;
}
}

 

This is html form

<form onSubmit="return formvalidations()" method="post"> input type="text" name="timeFrom" size="1" id="timeFrom" maxlength="2"> <input type="text" name="timeFrom1" size="1" id="timeFrom1" maxlength="2"> <input type="text" name="timeTo" size="1" id="timeTo" maxlength="2"> <input type="text" name="timeTo1" size="1" id="timeTo1" maxlength="2">

 

p/s: Thx for ur attention fenway!

Link to comment
https://forums.phpfreaks.com/topic/40300-input-validate/#findComment-199596
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.