Validation in PHP
1.Create a from
<!-- session security check-->
<?php $securityCheck = new Security(); $securityCheck->UserIsLogin(); ?>
<div id="page_content" style="height:680px;">
<!-- client side validation code -->
<script language="JavaScript">
function doValidation(objForm)
{
//return ;
objFormValidation = new glbDataValidation(objForm);
if(objFormValidation.isFieldValid( 'name', ' Name ', ' Required, LengthMax=255 ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
if(objFormValidation.isFieldValid( 'fatherName', ' Father\'s Name ', ' Required, LengthMax=255 ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
if(objFormValidation.isFieldValid( 'motherName', ' Mother\'s Name ', ' Required, LengthMax=200 ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
if(objFormValidation.isFieldValid( 'presentAddress', ' Present Address ', ' Required, LengthMax=255 ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
if(objFormValidation.isFieldValid( 'permanentAddress', ' Permanent Address ', ' Required, LengthMax=255 ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
/*if(objFormValidation.isFieldValid( 'passportNo', ' Passport No ', ' Required ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}*/
if(objFormValidation.isFieldValid( 'countryID', ' Country ', ' Required ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
if(objFormValidation.isFieldValid( 'gender', ' Gender ', ' Required ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
if(objFormValidation.isFieldValid( 'dateOfBirth', ' Date Of Birth ', ' Required ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
if(objFormValidation.isFieldValid( 'maritalStatus', ' Marital Status ', ' Required ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
/*if(objFormValidation.isFieldValid( 'religion', ' Religion ', ' Required ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}*/
/*if(document.getElementById('cUserPassword').value != document.getElementById('userPassword').value)
{
alert('Password Mismatch');
document.getElementById('cUserPassword').focus();
}*/
}
</script>
<?php
//$result_view=mysql_query("SELECT OWNER_ID FROM educations where OWNER_ID='$_SESSION[UserID]'");
//allreadyPost=mysql_num_rows($result_view);
$urlLeft = "";
if(!empty($_REQUEST['addMember']))
{
$urlLeft = "&addMember=yes&userID={$_REQUEST['userID']}";
}
if(!empty($_REQUEST['EmployeeID']))
{
//$title = "EDIT REFERENCE";
//$button = "Update";
$query = " SELECT *, SUBSTRING( HEIGHT, 1, 1 ) AS FEET, SUBSTRING( HEIGHT, -9, 2 ) AS INCHES
FROM employees WHERE USER_ID = {$_SESSION['UserID']} AND ISACTIVE = 1 AND EMPLOYEE_ID = {$_REQUEST['EmployeeID']}";
$employeePacket = SelectQuery($query);
$thisEmployeePacket = $employeePacket[0];
$urlLeft = "&EmployeeID={$thisEmployeePacket['EMPLOYEE_ID']}";
}
/*else
{
$title = "CREATE REFERENCE";
$button = "Insert";
}*/
// variable default section
$name = "";
if(!empty($thisEmployeePacket['NAME'])) $name = $thisEmployeePacket['NAME'];
if(!empty($_REQUEST['name'])) $name = $_REQUEST["name"];
$fatherName = '';
if(!empty($thisEmployeePacket['FATHER_NAME'])) $fatherName = $thisEmployeePacket['FATHER_NAME'];
if(!empty($_REQUEST['fatherName'])) $fatherName = $_REQUEST["fatherName"];
$motherName = '';
if(!empty($thisEmployeePacket['MOTHER_NAME'])) $motherName = $thisEmployeePacket['MOTHER_NAME'];
if(!empty($_REQUEST['motherName'])) $motherName = $_REQUEST["motherName"];
$presentAddress = '';
if(!empty($thisEmployeePacket['PRESENT_ADDRESS'])) $presentAddress = $thisEmployeePacket['PRESENT_ADDRESS'];
if(!empty($_REQUEST['presentAddress'])) $presentAddress = $_REQUEST["presentAddress"];
$permanentAddress = '';
if(!empty($thisEmployeePacket['PERMANENT_ADDRESS'])) $permanentAddress = $thisEmployeePacket['PERMANENT_ADDRESS'];
if(!empty($_REQUEST['permanentAddress'])) $permanentAddress = $_REQUEST["permanentAddress"];
$gender = '';
if(!empty($thisEmployeePacket['GENDER'])) $gender = $thisEmployeePacket['GENDER'];
if(!empty($_REQUEST['gender'])) $gender = $_REQUEST["gender"];
$dateOfBirth = '';
if(!empty($thisEmployeePacket['DATE_OF_BIRTH'])) $dateOfBirth = date('d-m-Y', strtotime($thisEmployeePacket['DATE_OF_BIRTH']));
if(!empty($_REQUEST['dateOfBirth'])) $dateOfBirth = date('d-m-Y', strtotime($_REQUEST["dateOfBirth"]));
$maritalStatus = '';
if(!empty($thisEmployeePacket['MARITAL_STATUS'])) $maritalStatus = $thisEmployeePacket['MARITAL_STATUS'];
if(!empty($_REQUEST['maritalStatus'])) $maritalStatus = $_REQUEST["maritalStatus"];
$religion = '';
if(!empty($thisEmployeePacket['RELIGION'])) $religion = $thisEmployeePacket['RELIGION'];
if(!empty($_REQUEST['religion'])) $religion = $_REQUEST["religion"];
$passportNo = '';
if(!empty($thisEmployeePacket['PASSPORT_NO'])) $passportNo = $thisEmployeePacket['PASSPORT_NO'];
if(!empty($_REQUEST['passportNo'])) $passportNo = $_REQUEST["passportNo"];
$countryID = '';
if(!empty($thisEmployeePacket['COUNTRY_ID'])) $countryID = $thisEmployeePacket['COUNTRY_ID'];
if(!empty($_REQUEST['countryID'])) $countryID = $_REQUEST["countryID"];
$heightFeet = '';
if(!empty($thisEmployeePacket['FEET'])) $heightFeet = $thisEmployeePacket['FEET'];
if(!empty($_REQUEST['heightFeet'])) $heightFeet = $_REQUEST["heightFeet"];
$heightInches = '';
if(!empty($thisEmployeePacket['INCHES'])) $heightInches = $thisEmployeePacket['INCHES'];
if(!empty($_REQUEST['heightInches'])) $heightInches = $_REQUEST["heightInches"];
// Set the error flags section
if(empty($error)) $error = false;
if(empty($errorMessage)) $errorMessage = "";
if(empty($nameError)) $nameError = false;
if(empty($fatherNameError)) $fatherNameError = false;
if(empty($motherNameError)) $motherNameError = false;
if(empty($presentAddressError)) $presentAddressError = false;
if(empty($permanentAddressError)) $permanentAddressError = false;
if(empty($passportNoError)) $passportNoError = false;
if(empty($countryIDError)) $countryIDError = false;
if(empty($genderError)) $genderError = false;
if(empty($dateOfBirthError)) $dateOfBirthError = false;
if(empty($religionError)) $religionError = false;
if(empty($maritalStatusError)) $maritalStatusError = false;
?>
<div align="center">
<?php if($error){?><div class="erroMessageLog"><ul><?php print $errorMessage;?></ul></div><?php }?>
<form name="step1Form" action="index.php?area=jobseeker&action=jobseeker-profile-action-step-1<?php echo $urlLeft;?>" method="post">
<table cellpadding="5" cellspacing="0" border="0" width="100%">
<tr>
<td align="left" class="resumeHeading">
<div>
» Personal Information </div> </td>
<td align="right" class="resumeHeading"><strong>Step-1</strong></td>
</tr>
<tr>
<td align="right"> </td>
<td align="left"> </td>
</tr>
<tr>
<td width="30%" align="right"><strong>Name :</strong></td>
<td align="left"><input type="text" name="name" value="<?php print $name;?>" style=" width:250px;" />
<?php if($nameError){ ?>
<span style="color:red;">* </span>
<?php }else{?>
<span>* </span> <?php } ?></td>
</tr>
<tr>
<td width="30%" align="right"><strong>Father's Name :</strong></td>
<td align="left"><input type="text" name="fatherName" value="<?php print $fatherName;?>" style=" width:250px;"><?php if($fatherNameError){ ?> <span style="color:red;">* </span> <?php }else{?> <span>* </span> <?php } ?></td>
</tr>
<tr>
<td width="30%" align="right"><strong>Mother's Name :</strong></td>
<td align="left"><input type="text" name="motherName" value="<?php print $motherName;?>" style=" width:250px;" />
<?php if($motherNameError){ ?> <span style="color:red;">* </span> <?php }else{?> <span>* </span> <?php } ?></td>
</tr>
<tr>
<td width="30%" align="right" valign="top"><strong>Present Address :</strong></td>
<td align="left"><span style="float:left;"><textarea name="presentAddress" rows="5" cols="15" class=" textarea" style=" width:250px;" ><?php print $presentAddress;?></textarea></span><?php if($presentAddressError){ ?> <span style="color:red;"> * </span> <?php }else{?> <span> * </span> <?php } ?></td>
</tr>
<tr>
<td width="30%" align="right" valign="top"><strong>Permanent Address :</strong></td>
<td align="left"><span style="float:left;"><textarea name="permanentAddress" rows="5" cols="15" class="textarea" style=" width:250px;"><?php print $permanentAddress;?></textarea></span><?php if($permanentAddressError){ ?> <span style="color:red;"> * </span> <?php }else{?> <span> * </span> <?php } ?></td>
</tr>
<tr>
<td width="30%" align="right" ><strong>Passport No. :</strong></td>
<td align="left"><input type="text" name="passportNo" value="<?php print $passportNo;?>" style=" width:250px;" ><?php if($passportNoError){ ?> <span style="color:red;">* </span> <?php }?></td>
</tr>
<tr>
<td width="30%" align="right"><strong>Nationality :</strong></td>
<td align="left">
<select type="text" name="countryID" style="width:253px; " class="inputText" >
<option value="">Select Country</option>
<?php
$query = " SELECT * FROM countrys WHERE 1 = 1 ORDER BY COUNTRY";
$countryPacket = SelectQuery($query);
foreach($countryPacket as $thisCountryPacket)
{
print "
<option value=\"{$thisCountryPacket['COUNTRY_ID']}\"
";
if($thisCountryPacket['COUNTRY_ID'] == $countryID) print " selected";
print ">{$thisCountryPacket['COUNTRY']}</option>
";
}
?>
</select><?php if($passportNoError){ ?> <span style="color:red;">* </span> <?php }else{?> <span> * </span> <?php } ?> </td>
</tr>
<tr>
<td align="right"><strong>Gender :</strong></td>
<td align="left">
<input type="radio" name="gender" value="Male" <?php if($gender == "Male") print "checked";?> />Male
<input type="radio" name="gender" value="Female" <?php if($gender == "Female") print "checked";?> />Female
<?php if($genderError){ ?> <span style="color:red;">* </span> <?php }else{?> <span> * </span> <?php } ?>
</td>
</tr>
<tr>
<td align="right"><strong>Date of Birth :</strong></td>
<td align="left">
<input type="text" name="dateOfBirth" value="<?php print $dateOfBirth;?>" readonly="readonly" size="10" style="width:250px" >
<img src="./skin/<?php echo $_REQUEST['skin']; ?>/images/calendar/cal.gif" width="16" height="16" alt="Pick a date" onClick="scwShow(scwID('dateOfBirth'),event);" style="cursor:pointer;"/>
<?php if($dateOfBirthError){ ?><span style="color:red;">* </span> <?php }else{?> <span> * </span> <?php } ?> </td>
</tr>
<tr>
<td align="right"><strong>Marital Status :</strong></td>
<td align="left">
<select name="maritalStatus" style="width:253px; " class="inputText" >
<option value="">Select</option>
<option value="Single" <?php if($maritalStatus == "Single") print "selected";?>>Single</option>
<option value="Married" <?php if($maritalStatus == "Married") print "selected";?>>Married</option>
<option value="Widowed" <?php if($maritalStatus == "Widowed") print "selected";?>>Widowed</option>
<option value="Divorced" <?php if($maritalStatus == "Divorced") print "selected";?>>Divorced</option>
<option value="Separated" <?php if($maritalStatus == "Separated") print "selected";?>>Separated</option>
</select><?php if($maritalStatusError){ ?> <span style="color:red;">* </span> <?php }else{?> <span> * </span> <?php } ?>
</td>
</tr>
<tr>
<td align="right"><strong>Height :</strong></td>
<td align="left">
<select name="heightFeet" class="inputText" style=" width:108px;">
<option value="">Select Feet</option>
<?php
for($i=3;$i<=8;$i++)
{
print "
<option value='{$i}'
";
if($heightFeet == $i) print "selected";
print">{$i}</option>
";
}
?>
</select> Feet
<select name="heightInches" class="inputText" style=" width:108px;">
<option value="0">Select Inches</option>
<?php
for($i=0;$i<=11;$i++)
{
print "
<option value='{$i}'
";
if($heightInches == $i) print "selected";
print">{$i}</option>
";
}
?>
</select> Inches </td>
</tr>
<tr>
<td align="right"><strong>Religion :</strong></td>
<td align="left">
<select name="religion" style="width:253px; " class="inputText" >
<option value="">Select Religion</option>
<option value="Islam" <?php if($religion == "Islam") print "selected";?>>Islam</option>
<option value="Hindu" <?php if($religion == "Hindu") print "selected";?>>Hindu</option>
<option value="Christian" <?php if($religion == "Christian") print "selected";?>>Christian</option>
<option value="Buddist" <?php if($religion == "Buddist") print "selected";?>>Buddist</option>
<option value="Others" <?php if($religion == "Others") print "selected";?>>Others</option>
</select>
<?php if($religionError){ ?> <span style="color:red;">*</span> <?php }?>
</td>
</tr>
<tr>
<td></td>
<td align="left">
<input type="hidden" value="<?php echo $urlLeft;?>" name="urlLeft">
<?php
if(!empty($_REQUEST['EmployeeID']))
{
?>
<input type="submit" value="Update" onclick="return doValidation(step1Form);" class="btton-details">
<?php
}
else
{
?>
<input type="submit" value="Next" onclick="return doValidation(step1Form);" class="btton-details">
<input type="submit" value="skip" name="skip" class="btton-details">
<?php
}
?>
</td>
</tr>
</table>
</form>
</div>
</div>
Javascript Validation
validation.js
// ************************************************************************
// * Begin Data Validation constructor
// ************************************************************************
function glbDataValidation(paramFormName){
/************************************************************
* Begin configure error message
************************************************************/
var REQUIRED = "The <fieldlabel> field is required";
var LENGTHMIN = "The <fieldlabel> field can not contain fewer than <length> characters.";
var LENGTHMAX = "The <fieldlabel> field can not contain more than <length> characters.";
var TEXTONLY = "The <fieldlabel> field must contain text only.";
var NUMONLY = "The <fieldlabel> field must contain only numbers.";
var NUMONLY_LT_MAXIMUM = "The <fieldlabel> field must be a number less than or equal to <maximum>.";
var NUMONLY_GT_MINIMUM = "The <fieldlabel> field must be a number greater than or equal to <minimum>.";
var ISMONEY = "The <fieldlabel> field must contain a numbers such as 200,000.00.";
var ISMONEY_DOLLARSIGN = "The <fieldlabel> field contains a dollar sign. Remove it and try again.";
var ISMONEY_LT_MAXIMUM = "The <fieldlabel> field must be a number less than or equal to <maximum>.";
var ISMONEY_GT_MINIMUM = "The <fieldlabel> field must be a number greater than or equal to <minimum>.";
var ISNUMFORMAT = "The <fieldlabel> field must contain only numbers.";
var ISNUMFORMAT_LT_MAXIMUM = "The <fieldlabel> field must be a number less than or equal to <maximum>.";
var ISNUMFORMAT_GT_MINIMUM = "The <fieldlabel> field must be a number greater than or equal to <minimum>.";
var ALPHACHARONLY = "The <fieldlabel> field must contain only letters from A-Z.";
var NOCHARONLY = "The <fieldlabel> field field must contain only letters from A-Z and numbers from 0-9";
var ISEMAIL = "The <fieldlabel> field contains an invalid email address\. Example: myname@domain\.com";
var COMPAREFIELD = "The <fieldlabel> does not confirm. Check the spelling then try again";
var ISUSERNAME = "The <fieldlabel> field is an invalid user name\.";
ISUSERNAME += "The <fieldlabel> accepts letters from A-Z, numbers from 0-9, \'_\', and \'-\'\.";
ISUSERNAME += "The <fieldlabel> must contain more than 4 and less than 30 characters\.";
var ISPASSWORD = "The <fieldlabel> field is an invalid password\.";
ISPASSWORD += " The field only accepts letters from A-Z, numbers from 0-9, \'_\', and \'-\'\.";
ISPASSWORD += " The field must contain more than 8 and less than 20 characters\.";
/************************************************************
* End configure error message
************************************************************/
/************************************************************
* Begin public methods
************************************************************/
this.isFieldValid = isFieldValid;
this.getErrorMessage = getErrorMessage;
this.doErrorAlertPrompt = doErrorAlertPrompt;
this.getFieldObject = getFieldObject;
this.isBlank = isBlank; // returns a true or false;
/************************************************************
* End public methods
************************************************************/
/************************************************************
* Begin create the form object if the client passes an object
* or an form name;
************************************************************/
var objForm = null;
if(typeof paramFormName == 'object'){ // if the client passes a form object
objForm = paramFormName;
} else { // if the user passes a form name
objForm = eval('document.'+paramFormName);
}
/************************************************************
* End create the form object if the client passes an object
************************************************************/
/************************************************************
* Begin variables/objects used by methods through out the component.
************************************************************/
var objField = null;
var strErrMessage = "";
/************************************************************
* End variables/objects used by methods through out the component.
************************************************************/
function getErrorMessage(){
return strErrMessage;
}
function doErrorAlertPrompt(){
alert(strErrMessage);
return false;
}
function setErrorMessage(msg){
strErrMessage = msg;
}
function getFieldObject(){
return objField;
}
function doErrorDetected(msg){
strErrMessage = msg;
blnErrorFlag = true;
}
function isBlank(s){ // This function is used to check for blank field
var checkchar = s.replace(/\s*\n*\t*\r*/g,'');
if (checkchar == ''){
return true;
} else {
return false;
}
}
function isFieldValid(frmFieldName,frmFriendlyName,frmValidate){
objField = eval('objForm'+'.'+frmFieldName);
blnErrorFlag = false;
// ************************************************************************
// * Begin prepare the field object variables use for validation
// ************************************************************************
var objTextProp = new Object();
objTextProp.frmFieldType = objField.type;
frmValidate = frmValidate.toLowerCase()
if(!objTextProp.frmFieldType){
objTextProp.frmFieldType = 'checked' ;
}
// ************************************************************************
// End prepare the field object variables use for validation
// ************************************************************************
// ************************************************************************
// *Begin Only Text, Textarea and Password fields can access the following code
// ************************************************************************
if (objTextProp.frmFieldType == 'text' || objTextProp.frmFieldType == 'textarea' ||
objTextProp.frmFieldType == 'password' || objTextProp.frmFieldType == 'hidden' ||
objTextProp.frmFieldType == 'file'){
if (blnErrorFlag == false && frmValidate.match(/required/g)){
if (isBlank(objField.value)){
msg = REQUIRED.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/lengthmin=\d*/g)){
var minlength = eval('"'+frmValidate.match(/lengthmin=\d*/g)+'"');
minlength = parseInt(minlength.match(/\d+/));
if (!isBlank(objField.value) && objField.value.length < minlength){
msg = LENGTHMIN.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<length>',minlength);
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/lengthmax=\d*/g)){
var maxlength = eval('"'+frmValidate.match(/lengthmax=\d*/g)+'"');
maxlength = parseInt(maxlength.match(/\d+/));
if (!isBlank(objField.value) && objField.value.length > maxlength){
msg = LENGTHMAX.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<length>',maxlength);
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/textonly/g)){
if (!isNaN(objField.value) && !isBlank(objField.value)){
msg = TEXTONLY.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
// Begin only number validations
if (blnErrorFlag == false && frmValidate.match(/numonly/g)){
if (isNaN(objField.value.replace(/[\.]/g,'a')) && !isBlank(objField.value) ){
msg = NUMONLY.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
if (!isNaN(objField.value.replace(/[\.]/g,'a'))
&& !isBlank(objField.value) ){
tmpMinMaxValue = frmValidate.match(/numonly\[[\d]+,[\d]+\]/g);
if(tmpMinMaxValue){
// Begin build the array
tmpMinMaxValue2 = ''+frmValidate.match(/numonly\[[\d]+,[\d]+\]/g);
tmpMinMaxValue2 = eval(tmpMinMaxValue2.replace(/numonly/,''));
tmpMinValue = tmpMinMaxValue2[0] // Min
tmpMaxValue = tmpMinMaxValue2[1] // Max
// End build the array
// Begin check to see if the developer has the number range correct.
// Else check the validation.
if(tmpMinValue > tmpMaxValue){
alert('Component Error: The Minimun can not greater that the Maximum');
return false;
// Begin check to see if the developer has the number range correct.
} else {
if(objField.value.replace(/[\.]/g,'a') < tmpMinValue){
msg = NUMONLY_GT_MINIMUM.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<minimum>',tmpMinValue);
doErrorDetected(msg);
} else if(objField.value.replace(/[\.]/g,'a') > tmpMaxValue){
msg = NUMONLY_LT_MAXIMUM.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<maximum>',tmpMaxValue);
doErrorDetected(msg);
}
}
}
}
}
// End only number validations
// Begin money format.
if (blnErrorFlag == false && frmValidate.match(/ismoney/g)){
if (isNaN(objField.value.replace(/[,$]/g,''))
&& !isBlank(objField.value)){
msg = ISMONEY.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
} else if(objField.value.match(/[$]/g)) {
msg = ISMONEY_DOLLARSIGN.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
if (!blnErrorFlag){
tmpMinMaxValue = frmValidate.match(/ismoney\[[\d]+,[\d]+\]/g);
if(tmpMinMaxValue){
// Begin build the array
tmpMinMaxValue2 = ''+frmValidate.match(/ismoney\[[\d]+,[\d]+\]/g);
tmpMinMaxValue2 = eval(tmpMinMaxValue2.replace(/ismoney/,''));
tmpMinValue = tmpMinMaxValue2[0] // Min
tmpMaxValue = tmpMinMaxValue2[1] // Max
// End build the array
// Begin check to see if the developer has the number range correct.
// Else check the validation.
if(tmpMinValue > tmpMaxValue){
alert('Component Error: The Minimun can not greater that the Maximum');
return false;
} else {
// End check to see if the developer has the number range correct.
if(objField.value.replace(/[,$]/g,'') < tmpMinValue){
msg = ISMONEY_GT_MINIMUM.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<minimum>',tmpMinValue);
doErrorDetected(msg);
} else if(objField.value.replace(/[,$]/g,'') > tmpMaxValue){
msg = ISMONEY_LT_MAXIMUM.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<maximum>',tmpMinValue);
doErrorDetected(msg);
}
}
}
}
}
// End money format.
// Begin Number Format
if (blnErrorFlag == false && frmValidate.match(/isnumformat/g)){
if (isNaN(objField.value.replace(/[,]/g,''))
&& !isBlank(objField.value) ){
msg = ISNUMFORMAT.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
if (!blnErrorFlag){
tmpMinMaxValue = frmValidate.match(/isnumformat\[[\d]+,[\d]+\]/g);
if(tmpMinMaxValue){
// Begin build the array
tmpMinMaxValue2 = ''+frmValidate.match(/isnumformat\[[\d]+,[\d]+\]/g);
tmpMinMaxValue2 = eval(tmpMinMaxValue2.replace(/isnumformat/,''));
tmpMinValue = tmpMinMaxValue2[0] // Min
tmpMaxValue = tmpMinMaxValue2[1] // Max
// End build the array
if(tmpMinValue > tmpMaxValue){
alert('Component Error: The Minimun can not greater that the Maximum');
return false;
} else {
if(objField.value.replace(/[,]/g,'') < tmpMinValue){
msg = ISNUMFORMAT_GT_MINIMUM.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<minimum>',tmpMinValue);
doErrorDetected(msg);
} else if(objField.value.replace(/[,]/g,'') > tmpMaxValue){
msg = ISNUMFORMAT_GT_MINIMUM.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<minimum>',tmpMaxValue);
doErrorDetected(msg);
}
}
}
}
}
//End Number Format
if (blnErrorFlag == false && frmValidate.match(/alphacharonly/g)){
if (objField.value.replace(/(([a-z])*)(([A-Z])*)/g,'') != ''
&& !isBlank(objField.value)){
msg = ALPHACHARONLY.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/nocharonly/g)){
if (eval(objField.value.replace(/(([a-z])*)(([A-Z])*)(\d*)/g,'')) != ''
&& !isBlank(objField.value)){
msg = NOCHARONLY.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/isemail/g)){
if (eval(objField.value.match(/\w@\w+\.\w{2,3}/g)) == null
&& !isBlank(objField.value)){
msg = ISEMAIL.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/comparefield/g)){
var txtFieldObject = eval('"'+frmValidate.match(/comparefield=\w*.\w*.\w*/g)+'"')
txtFieldObject = txtFieldObject.replace(/CompareField=/,'')
if (eval(objField.value) != eval(txtFieldObject+'.value')){
msg = COMPAREFIELD.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/isusername/g)){
if (
(
(objField.value.match(/[aA-zZ|0-9|_|-]+/g)
!= objField.value)
&& !isBlank(objField.value)
)
||
(
(objField.value.length < 4) || (objField.value.length > 30))
){
msg = ISUSERNAME.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/ispassword/g)){
if (
(
(objField.value.match(/[aA-zZ|0-9|_|-]+/g)
!= objField.value)
&& !isBlank(objField.value)
)
||
(
(objField.value).length < 8 || eval(objField.value.length > 20)
)
){
msg = ISPASSWORD.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
}
// ************************************************************************
// *End Only Text, Textarea and Password fields can access the following code
// ************************************************************************
// ************************************************************************
// * Only OPTION fields can access the following code
// ************************************************************************
if (objTextProp.frmFieldType == 'select-multiple' || objTextProp.frmFieldType == 'select-one'){
if (blnErrorFlag == false && frmValidate.match(/required/g)){
var strSelectedValue = '';
var strSelectedLength = 0;
for (var i = 0; i < objField.length; i++) { // Loop through the selected items to create the strSelectedValue
if (objField.options[i].selected){
strSelectedValue = strSelectedValue += objField.options[i].value;
}
}
if (strSelectedValue == ''){
msg = REQUIRED.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/lengthmin=\d*/g)){
var strSelectedLength = 0;
var minlength = eval('"'+frmValidate.match(/lengthmin=\d*/g)+'"');
minlength = parseInt(minlength.match(/\d+/));
for (var i = 0; i < objField.length; i++) { // Loop through the selected items to create the strSelectedValue
if (objField.options[i].selected){
++strSelectedLength;
}
}
if (strSelectedLength < minlength){
msg = LENGTHMIN.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<length>',minlength);
if(minlength == 1){
msg += ".";
} else {
msg += "s.";
}
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/lengthmax=\d*/g)){
var strSelectedLength = 0;
var maxlength = eval('"'+frmValidate.match(/lengthmax=\d*/g)+'"');
maxlength = parseInt(maxlength.match(/\d+/));
for (var i = 0; i < objField.length; i++) { // Loop through the selected items to create the strSelectedValue
if (objField.options[i].selected){
strSelectedLength = strSelectedLength+1;
}
}
if (strSelectedLength > maxlength ){
msg = LENGTHMAX.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<length>',maxlength);
doErrorDetected(msg);
}
}
}
// ************************************************************************
// * End of Only OPTION fields can access the following code
// ************************************************************************
// ************************************************************************
// * Only radio and check box fields can access the following code
// ************************************************************************
if (objTextProp.frmFieldType == 'checked'){
if (blnErrorFlag == false && frmValidate.match(/required/g)){
var strSelectedValue = '';
for (i = 0, j = objField.length; i < j; i++) { // Loop through the selected items to create the strSelectedValue
if (objField[i].checked == true){
strSelectedValue = strSelectedValue += objField[i].value;
}
}
if (strSelectedValue == ''){
msg = REQUIRED.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/lengthmin=\d*/g)){
var strSelectedLength = 0
var minlength = eval('"'+frmValidate.match(/lengthmin=\d*/g)+'"');
minlength = parseInt(minlength.match(/\d+/));
for (i = 0, j = objField.length; i < j; i++) { // Loop through the selected items to create the strSelectedValue
if (objField[i].checked == true){
++strSelectedLength;
}
}
if (strSelectedLength < minlength){
msg = LENGTHMIN.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<length>',minlength);
if(minlength == 1){
msg += ".";
} else {
msg += "s.";
}
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/lengthmax=\d*/g)){
var strSelectedLength = 0
var maxlength = eval('"'+frmValidate.match(/lengthmax=\d*/g)+'"');
maxlength = parseInt(maxlength.match(/\d+/));
for (i = 0, j = objField.length; i < j; i++) { // Loop through the selected items to create the strSelectedValue
if (objField[i].checked == true){
++strSelectedLength;
}
}
if (strSelectedLength > maxlength){
msg = LENGTHMAX.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<length>',maxlength);
doErrorDetected(msg);
}
}
}
// ************************************************************************
// * End of only radio and check box fields can access the following code
// ************************************************************************
// Begn the return value sent back let the client know the field pass or failed
// the validation
return blnErrorFlag;
// End the return value sent back let the client know the field pass or failed
}
}
function Confirmit(mess) {
var confirmVar=confirm(mess);
return confirmVar;
}
// ************************************************************************
// * A new function added to check for valid dates
// ************************************************************************
function isDate(dateStr) {
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
return false;
}
month = matchArray[1]; // p@rse date into variables
day = matchArray[3];
year = matchArray[5];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn`t have 31 days!")
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day==29 && !isleap)) {
alert("February " + year + " doesn`t have " + day + " days!");
return false;
}
}
return true; // date is valid
}
function isEuroDate(dateStr) {
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
return false;
}
day = matchArray[1]; // p@rse date into variables
month = matchArray[3];
year = matchArray[5];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn`t have 31 days!")
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day==29 && !isleap)) {
alert("February " + year + " doesn`t have " + day + " days!");
return false;
}
}
return true; // date is valid
}
<!-- session security check-->
<?php $securityCheck = new Security(); $securityCheck->UserIsLogin(); ?>
<div id="page_content" style="height:680px;">
<!-- client side validation code -->
<script language="JavaScript">
function doValidation(objForm)
{
//return ;
objFormValidation = new glbDataValidation(objForm);
if(objFormValidation.isFieldValid( 'name', ' Name ', ' Required, LengthMax=255 ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
if(objFormValidation.isFieldValid( 'fatherName', ' Father\'s Name ', ' Required, LengthMax=255 ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
if(objFormValidation.isFieldValid( 'motherName', ' Mother\'s Name ', ' Required, LengthMax=200 ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
if(objFormValidation.isFieldValid( 'presentAddress', ' Present Address ', ' Required, LengthMax=255 ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
if(objFormValidation.isFieldValid( 'permanentAddress', ' Permanent Address ', ' Required, LengthMax=255 ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
/*if(objFormValidation.isFieldValid( 'passportNo', ' Passport No ', ' Required ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}*/
if(objFormValidation.isFieldValid( 'countryID', ' Country ', ' Required ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
if(objFormValidation.isFieldValid( 'gender', ' Gender ', ' Required ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
if(objFormValidation.isFieldValid( 'dateOfBirth', ' Date Of Birth ', ' Required ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
if(objFormValidation.isFieldValid( 'maritalStatus', ' Marital Status ', ' Required ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}
/*if(objFormValidation.isFieldValid( 'religion', ' Religion ', ' Required ' ))
{
objField = objFormValidation.getFieldObject();
objField.focus();
return objFormValidation.doErrorAlertPrompt();
}*/
/*if(document.getElementById('cUserPassword').value != document.getElementById('userPassword').value)
{
alert('Password Mismatch');
document.getElementById('cUserPassword').focus();
}*/
}
</script>
<?php
//$result_view=mysql_query("SELECT OWNER_ID FROM educations where OWNER_ID='$_SESSION[UserID]'");
//allreadyPost=mysql_num_rows($result_view);
$urlLeft = "";
if(!empty($_REQUEST['addMember']))
{
$urlLeft = "&addMember=yes&userID={$_REQUEST['userID']}";
}
if(!empty($_REQUEST['EmployeeID']))
{
//$title = "EDIT REFERENCE";
//$button = "Update";
$query = " SELECT *, SUBSTRING( HEIGHT, 1, 1 ) AS FEET, SUBSTRING( HEIGHT, -9, 2 ) AS INCHES
FROM employees WHERE USER_ID = {$_SESSION['UserID']} AND ISACTIVE = 1 AND EMPLOYEE_ID = {$_REQUEST['EmployeeID']}";
$employeePacket = SelectQuery($query);
$thisEmployeePacket = $employeePacket[0];
$urlLeft = "&EmployeeID={$thisEmployeePacket['EMPLOYEE_ID']}";
}
/*else
{
$title = "CREATE REFERENCE";
$button = "Insert";
}*/
// variable default section
$name = "";
if(!empty($thisEmployeePacket['NAME'])) $name = $thisEmployeePacket['NAME'];
if(!empty($_REQUEST['name'])) $name = $_REQUEST["name"];
$fatherName = '';
if(!empty($thisEmployeePacket['FATHER_NAME'])) $fatherName = $thisEmployeePacket['FATHER_NAME'];
if(!empty($_REQUEST['fatherName'])) $fatherName = $_REQUEST["fatherName"];
$motherName = '';
if(!empty($thisEmployeePacket['MOTHER_NAME'])) $motherName = $thisEmployeePacket['MOTHER_NAME'];
if(!empty($_REQUEST['motherName'])) $motherName = $_REQUEST["motherName"];
$presentAddress = '';
if(!empty($thisEmployeePacket['PRESENT_ADDRESS'])) $presentAddress = $thisEmployeePacket['PRESENT_ADDRESS'];
if(!empty($_REQUEST['presentAddress'])) $presentAddress = $_REQUEST["presentAddress"];
$permanentAddress = '';
if(!empty($thisEmployeePacket['PERMANENT_ADDRESS'])) $permanentAddress = $thisEmployeePacket['PERMANENT_ADDRESS'];
if(!empty($_REQUEST['permanentAddress'])) $permanentAddress = $_REQUEST["permanentAddress"];
$gender = '';
if(!empty($thisEmployeePacket['GENDER'])) $gender = $thisEmployeePacket['GENDER'];
if(!empty($_REQUEST['gender'])) $gender = $_REQUEST["gender"];
$dateOfBirth = '';
if(!empty($thisEmployeePacket['DATE_OF_BIRTH'])) $dateOfBirth = date('d-m-Y', strtotime($thisEmployeePacket['DATE_OF_BIRTH']));
if(!empty($_REQUEST['dateOfBirth'])) $dateOfBirth = date('d-m-Y', strtotime($_REQUEST["dateOfBirth"]));
$maritalStatus = '';
if(!empty($thisEmployeePacket['MARITAL_STATUS'])) $maritalStatus = $thisEmployeePacket['MARITAL_STATUS'];
if(!empty($_REQUEST['maritalStatus'])) $maritalStatus = $_REQUEST["maritalStatus"];
$religion = '';
if(!empty($thisEmployeePacket['RELIGION'])) $religion = $thisEmployeePacket['RELIGION'];
if(!empty($_REQUEST['religion'])) $religion = $_REQUEST["religion"];
$passportNo = '';
if(!empty($thisEmployeePacket['PASSPORT_NO'])) $passportNo = $thisEmployeePacket['PASSPORT_NO'];
if(!empty($_REQUEST['passportNo'])) $passportNo = $_REQUEST["passportNo"];
$countryID = '';
if(!empty($thisEmployeePacket['COUNTRY_ID'])) $countryID = $thisEmployeePacket['COUNTRY_ID'];
if(!empty($_REQUEST['countryID'])) $countryID = $_REQUEST["countryID"];
$heightFeet = '';
if(!empty($thisEmployeePacket['FEET'])) $heightFeet = $thisEmployeePacket['FEET'];
if(!empty($_REQUEST['heightFeet'])) $heightFeet = $_REQUEST["heightFeet"];
$heightInches = '';
if(!empty($thisEmployeePacket['INCHES'])) $heightInches = $thisEmployeePacket['INCHES'];
if(!empty($_REQUEST['heightInches'])) $heightInches = $_REQUEST["heightInches"];
// Set the error flags section
if(empty($error)) $error = false;
if(empty($errorMessage)) $errorMessage = "";
if(empty($nameError)) $nameError = false;
if(empty($fatherNameError)) $fatherNameError = false;
if(empty($motherNameError)) $motherNameError = false;
if(empty($presentAddressError)) $presentAddressError = false;
if(empty($permanentAddressError)) $permanentAddressError = false;
if(empty($passportNoError)) $passportNoError = false;
if(empty($countryIDError)) $countryIDError = false;
if(empty($genderError)) $genderError = false;
if(empty($dateOfBirthError)) $dateOfBirthError = false;
if(empty($religionError)) $religionError = false;
if(empty($maritalStatusError)) $maritalStatusError = false;
?>
<div align="center">
<?php if($error){?><div class="erroMessageLog"><ul><?php print $errorMessage;?></ul></div><?php }?>
<form name="step1Form" action="index.php?area=jobseeker&action=jobseeker-profile-action-step-1<?php echo $urlLeft;?>" method="post">
<table cellpadding="5" cellspacing="0" border="0" width="100%">
<tr>
<td align="left" class="resumeHeading">
<div>
» Personal Information </div> </td>
<td align="right" class="resumeHeading"><strong>Step-1</strong></td>
</tr>
<tr>
<td align="right"> </td>
<td align="left"> </td>
</tr>
<tr>
<td width="30%" align="right"><strong>Name :</strong></td>
<td align="left"><input type="text" name="name" value="<?php print $name;?>" style=" width:250px;" />
<?php if($nameError){ ?>
<span style="color:red;">* </span>
<?php }else{?>
<span>* </span> <?php } ?></td>
</tr>
<tr>
<td width="30%" align="right"><strong>Father's Name :</strong></td>
<td align="left"><input type="text" name="fatherName" value="<?php print $fatherName;?>" style=" width:250px;"><?php if($fatherNameError){ ?> <span style="color:red;">* </span> <?php }else{?> <span>* </span> <?php } ?></td>
</tr>
<tr>
<td width="30%" align="right"><strong>Mother's Name :</strong></td>
<td align="left"><input type="text" name="motherName" value="<?php print $motherName;?>" style=" width:250px;" />
<?php if($motherNameError){ ?> <span style="color:red;">* </span> <?php }else{?> <span>* </span> <?php } ?></td>
</tr>
<tr>
<td width="30%" align="right" valign="top"><strong>Present Address :</strong></td>
<td align="left"><span style="float:left;"><textarea name="presentAddress" rows="5" cols="15" class=" textarea" style=" width:250px;" ><?php print $presentAddress;?></textarea></span><?php if($presentAddressError){ ?> <span style="color:red;"> * </span> <?php }else{?> <span> * </span> <?php } ?></td>
</tr>
<tr>
<td width="30%" align="right" valign="top"><strong>Permanent Address :</strong></td>
<td align="left"><span style="float:left;"><textarea name="permanentAddress" rows="5" cols="15" class="textarea" style=" width:250px;"><?php print $permanentAddress;?></textarea></span><?php if($permanentAddressError){ ?> <span style="color:red;"> * </span> <?php }else{?> <span> * </span> <?php } ?></td>
</tr>
<tr>
<td width="30%" align="right" ><strong>Passport No. :</strong></td>
<td align="left"><input type="text" name="passportNo" value="<?php print $passportNo;?>" style=" width:250px;" ><?php if($passportNoError){ ?> <span style="color:red;">* </span> <?php }?></td>
</tr>
<tr>
<td width="30%" align="right"><strong>Nationality :</strong></td>
<td align="left">
<select type="text" name="countryID" style="width:253px; " class="inputText" >
<option value="">Select Country</option>
<?php
$query = " SELECT * FROM countrys WHERE 1 = 1 ORDER BY COUNTRY";
$countryPacket = SelectQuery($query);
foreach($countryPacket as $thisCountryPacket)
{
print "
<option value=\"{$thisCountryPacket['COUNTRY_ID']}\"
";
if($thisCountryPacket['COUNTRY_ID'] == $countryID) print " selected";
print ">{$thisCountryPacket['COUNTRY']}</option>
";
}
?>
</select><?php if($passportNoError){ ?> <span style="color:red;">* </span> <?php }else{?> <span> * </span> <?php } ?> </td>
</tr>
<tr>
<td align="right"><strong>Gender :</strong></td>
<td align="left">
<input type="radio" name="gender" value="Male" <?php if($gender == "Male") print "checked";?> />Male
<input type="radio" name="gender" value="Female" <?php if($gender == "Female") print "checked";?> />Female
<?php if($genderError){ ?> <span style="color:red;">* </span> <?php }else{?> <span> * </span> <?php } ?>
</td>
</tr>
<tr>
<td align="right"><strong>Date of Birth :</strong></td>
<td align="left">
<input type="text" name="dateOfBirth" value="<?php print $dateOfBirth;?>" readonly="readonly" size="10" style="width:250px" >
<img src="./skin/<?php echo $_REQUEST['skin']; ?>/images/calendar/cal.gif" width="16" height="16" alt="Pick a date" onClick="scwShow(scwID('dateOfBirth'),event);" style="cursor:pointer;"/>
<?php if($dateOfBirthError){ ?><span style="color:red;">* </span> <?php }else{?> <span> * </span> <?php } ?> </td>
</tr>
<tr>
<td align="right"><strong>Marital Status :</strong></td>
<td align="left">
<select name="maritalStatus" style="width:253px; " class="inputText" >
<option value="">Select</option>
<option value="Single" <?php if($maritalStatus == "Single") print "selected";?>>Single</option>
<option value="Married" <?php if($maritalStatus == "Married") print "selected";?>>Married</option>
<option value="Widowed" <?php if($maritalStatus == "Widowed") print "selected";?>>Widowed</option>
<option value="Divorced" <?php if($maritalStatus == "Divorced") print "selected";?>>Divorced</option>
<option value="Separated" <?php if($maritalStatus == "Separated") print "selected";?>>Separated</option>
</select><?php if($maritalStatusError){ ?> <span style="color:red;">* </span> <?php }else{?> <span> * </span> <?php } ?>
</td>
</tr>
<tr>
<td align="right"><strong>Height :</strong></td>
<td align="left">
<select name="heightFeet" class="inputText" style=" width:108px;">
<option value="">Select Feet</option>
<?php
for($i=3;$i<=8;$i++)
{
print "
<option value='{$i}'
";
if($heightFeet == $i) print "selected";
print">{$i}</option>
";
}
?>
</select> Feet
<select name="heightInches" class="inputText" style=" width:108px;">
<option value="0">Select Inches</option>
<?php
for($i=0;$i<=11;$i++)
{
print "
<option value='{$i}'
";
if($heightInches == $i) print "selected";
print">{$i}</option>
";
}
?>
</select> Inches </td>
</tr>
<tr>
<td align="right"><strong>Religion :</strong></td>
<td align="left">
<select name="religion" style="width:253px; " class="inputText" >
<option value="">Select Religion</option>
<option value="Islam" <?php if($religion == "Islam") print "selected";?>>Islam</option>
<option value="Hindu" <?php if($religion == "Hindu") print "selected";?>>Hindu</option>
<option value="Christian" <?php if($religion == "Christian") print "selected";?>>Christian</option>
<option value="Buddist" <?php if($religion == "Buddist") print "selected";?>>Buddist</option>
<option value="Others" <?php if($religion == "Others") print "selected";?>>Others</option>
</select>
<?php if($religionError){ ?> <span style="color:red;">*</span> <?php }?>
</td>
</tr>
<tr>
<td></td>
<td align="left">
<input type="hidden" value="<?php echo $urlLeft;?>" name="urlLeft">
<?php
if(!empty($_REQUEST['EmployeeID']))
{
?>
<input type="submit" value="Update" onclick="return doValidation(step1Form);" class="btton-details">
<?php
}
else
{
?>
<input type="submit" value="Next" onclick="return doValidation(step1Form);" class="btton-details">
<input type="submit" value="skip" name="skip" class="btton-details">
<?php
}
?>
</td>
</tr>
</table>
</form>
</div>
</div>
Javascript Validation
validation.js
// ************************************************************************
// * Begin Data Validation constructor
// ************************************************************************
function glbDataValidation(paramFormName){
/************************************************************
* Begin configure error message
************************************************************/
var REQUIRED = "The <fieldlabel> field is required";
var LENGTHMIN = "The <fieldlabel> field can not contain fewer than <length> characters.";
var LENGTHMAX = "The <fieldlabel> field can not contain more than <length> characters.";
var TEXTONLY = "The <fieldlabel> field must contain text only.";
var NUMONLY = "The <fieldlabel> field must contain only numbers.";
var NUMONLY_LT_MAXIMUM = "The <fieldlabel> field must be a number less than or equal to <maximum>.";
var NUMONLY_GT_MINIMUM = "The <fieldlabel> field must be a number greater than or equal to <minimum>.";
var ISMONEY = "The <fieldlabel> field must contain a numbers such as 200,000.00.";
var ISMONEY_DOLLARSIGN = "The <fieldlabel> field contains a dollar sign. Remove it and try again.";
var ISMONEY_LT_MAXIMUM = "The <fieldlabel> field must be a number less than or equal to <maximum>.";
var ISMONEY_GT_MINIMUM = "The <fieldlabel> field must be a number greater than or equal to <minimum>.";
var ISNUMFORMAT = "The <fieldlabel> field must contain only numbers.";
var ISNUMFORMAT_LT_MAXIMUM = "The <fieldlabel> field must be a number less than or equal to <maximum>.";
var ISNUMFORMAT_GT_MINIMUM = "The <fieldlabel> field must be a number greater than or equal to <minimum>.";
var ALPHACHARONLY = "The <fieldlabel> field must contain only letters from A-Z.";
var NOCHARONLY = "The <fieldlabel> field field must contain only letters from A-Z and numbers from 0-9";
var ISEMAIL = "The <fieldlabel> field contains an invalid email address\. Example: myname@domain\.com";
var COMPAREFIELD = "The <fieldlabel> does not confirm. Check the spelling then try again";
var ISUSERNAME = "The <fieldlabel> field is an invalid user name\.";
ISUSERNAME += "The <fieldlabel> accepts letters from A-Z, numbers from 0-9, \'_\', and \'-\'\.";
ISUSERNAME += "The <fieldlabel> must contain more than 4 and less than 30 characters\.";
var ISPASSWORD = "The <fieldlabel> field is an invalid password\.";
ISPASSWORD += " The field only accepts letters from A-Z, numbers from 0-9, \'_\', and \'-\'\.";
ISPASSWORD += " The field must contain more than 8 and less than 20 characters\.";
/************************************************************
* End configure error message
************************************************************/
/************************************************************
* Begin public methods
************************************************************/
this.isFieldValid = isFieldValid;
this.getErrorMessage = getErrorMessage;
this.doErrorAlertPrompt = doErrorAlertPrompt;
this.getFieldObject = getFieldObject;
this.isBlank = isBlank; // returns a true or false;
/************************************************************
* End public methods
************************************************************/
/************************************************************
* Begin create the form object if the client passes an object
* or an form name;
************************************************************/
var objForm = null;
if(typeof paramFormName == 'object'){ // if the client passes a form object
objForm = paramFormName;
} else { // if the user passes a form name
objForm = eval('document.'+paramFormName);
}
/************************************************************
* End create the form object if the client passes an object
************************************************************/
/************************************************************
* Begin variables/objects used by methods through out the component.
************************************************************/
var objField = null;
var strErrMessage = "";
/************************************************************
* End variables/objects used by methods through out the component.
************************************************************/
function getErrorMessage(){
return strErrMessage;
}
function doErrorAlertPrompt(){
alert(strErrMessage);
return false;
}
function setErrorMessage(msg){
strErrMessage = msg;
}
function getFieldObject(){
return objField;
}
function doErrorDetected(msg){
strErrMessage = msg;
blnErrorFlag = true;
}
function isBlank(s){ // This function is used to check for blank field
var checkchar = s.replace(/\s*\n*\t*\r*/g,'');
if (checkchar == ''){
return true;
} else {
return false;
}
}
function isFieldValid(frmFieldName,frmFriendlyName,frmValidate){
objField = eval('objForm'+'.'+frmFieldName);
blnErrorFlag = false;
// ************************************************************************
// * Begin prepare the field object variables use for validation
// ************************************************************************
var objTextProp = new Object();
objTextProp.frmFieldType = objField.type;
frmValidate = frmValidate.toLowerCase()
if(!objTextProp.frmFieldType){
objTextProp.frmFieldType = 'checked' ;
}
// ************************************************************************
// End prepare the field object variables use for validation
// ************************************************************************
// ************************************************************************
// *Begin Only Text, Textarea and Password fields can access the following code
// ************************************************************************
if (objTextProp.frmFieldType == 'text' || objTextProp.frmFieldType == 'textarea' ||
objTextProp.frmFieldType == 'password' || objTextProp.frmFieldType == 'hidden' ||
objTextProp.frmFieldType == 'file'){
if (blnErrorFlag == false && frmValidate.match(/required/g)){
if (isBlank(objField.value)){
msg = REQUIRED.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/lengthmin=\d*/g)){
var minlength = eval('"'+frmValidate.match(/lengthmin=\d*/g)+'"');
minlength = parseInt(minlength.match(/\d+/));
if (!isBlank(objField.value) && objField.value.length < minlength){
msg = LENGTHMIN.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<length>',minlength);
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/lengthmax=\d*/g)){
var maxlength = eval('"'+frmValidate.match(/lengthmax=\d*/g)+'"');
maxlength = parseInt(maxlength.match(/\d+/));
if (!isBlank(objField.value) && objField.value.length > maxlength){
msg = LENGTHMAX.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<length>',maxlength);
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/textonly/g)){
if (!isNaN(objField.value) && !isBlank(objField.value)){
msg = TEXTONLY.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
// Begin only number validations
if (blnErrorFlag == false && frmValidate.match(/numonly/g)){
if (isNaN(objField.value.replace(/[\.]/g,'a')) && !isBlank(objField.value) ){
msg = NUMONLY.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
if (!isNaN(objField.value.replace(/[\.]/g,'a'))
&& !isBlank(objField.value) ){
tmpMinMaxValue = frmValidate.match(/numonly\[[\d]+,[\d]+\]/g);
if(tmpMinMaxValue){
// Begin build the array
tmpMinMaxValue2 = ''+frmValidate.match(/numonly\[[\d]+,[\d]+\]/g);
tmpMinMaxValue2 = eval(tmpMinMaxValue2.replace(/numonly/,''));
tmpMinValue = tmpMinMaxValue2[0] // Min
tmpMaxValue = tmpMinMaxValue2[1] // Max
// End build the array
// Begin check to see if the developer has the number range correct.
// Else check the validation.
if(tmpMinValue > tmpMaxValue){
alert('Component Error: The Minimun can not greater that the Maximum');
return false;
// Begin check to see if the developer has the number range correct.
} else {
if(objField.value.replace(/[\.]/g,'a') < tmpMinValue){
msg = NUMONLY_GT_MINIMUM.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<minimum>',tmpMinValue);
doErrorDetected(msg);
} else if(objField.value.replace(/[\.]/g,'a') > tmpMaxValue){
msg = NUMONLY_LT_MAXIMUM.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<maximum>',tmpMaxValue);
doErrorDetected(msg);
}
}
}
}
}
// End only number validations
// Begin money format.
if (blnErrorFlag == false && frmValidate.match(/ismoney/g)){
if (isNaN(objField.value.replace(/[,$]/g,''))
&& !isBlank(objField.value)){
msg = ISMONEY.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
} else if(objField.value.match(/[$]/g)) {
msg = ISMONEY_DOLLARSIGN.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
if (!blnErrorFlag){
tmpMinMaxValue = frmValidate.match(/ismoney\[[\d]+,[\d]+\]/g);
if(tmpMinMaxValue){
// Begin build the array
tmpMinMaxValue2 = ''+frmValidate.match(/ismoney\[[\d]+,[\d]+\]/g);
tmpMinMaxValue2 = eval(tmpMinMaxValue2.replace(/ismoney/,''));
tmpMinValue = tmpMinMaxValue2[0] // Min
tmpMaxValue = tmpMinMaxValue2[1] // Max
// End build the array
// Begin check to see if the developer has the number range correct.
// Else check the validation.
if(tmpMinValue > tmpMaxValue){
alert('Component Error: The Minimun can not greater that the Maximum');
return false;
} else {
// End check to see if the developer has the number range correct.
if(objField.value.replace(/[,$]/g,'') < tmpMinValue){
msg = ISMONEY_GT_MINIMUM.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<minimum>',tmpMinValue);
doErrorDetected(msg);
} else if(objField.value.replace(/[,$]/g,'') > tmpMaxValue){
msg = ISMONEY_LT_MAXIMUM.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<maximum>',tmpMinValue);
doErrorDetected(msg);
}
}
}
}
}
// End money format.
// Begin Number Format
if (blnErrorFlag == false && frmValidate.match(/isnumformat/g)){
if (isNaN(objField.value.replace(/[,]/g,''))
&& !isBlank(objField.value) ){
msg = ISNUMFORMAT.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
if (!blnErrorFlag){
tmpMinMaxValue = frmValidate.match(/isnumformat\[[\d]+,[\d]+\]/g);
if(tmpMinMaxValue){
// Begin build the array
tmpMinMaxValue2 = ''+frmValidate.match(/isnumformat\[[\d]+,[\d]+\]/g);
tmpMinMaxValue2 = eval(tmpMinMaxValue2.replace(/isnumformat/,''));
tmpMinValue = tmpMinMaxValue2[0] // Min
tmpMaxValue = tmpMinMaxValue2[1] // Max
// End build the array
if(tmpMinValue > tmpMaxValue){
alert('Component Error: The Minimun can not greater that the Maximum');
return false;
} else {
if(objField.value.replace(/[,]/g,'') < tmpMinValue){
msg = ISNUMFORMAT_GT_MINIMUM.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<minimum>',tmpMinValue);
doErrorDetected(msg);
} else if(objField.value.replace(/[,]/g,'') > tmpMaxValue){
msg = ISNUMFORMAT_GT_MINIMUM.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<minimum>',tmpMaxValue);
doErrorDetected(msg);
}
}
}
}
}
//End Number Format
if (blnErrorFlag == false && frmValidate.match(/alphacharonly/g)){
if (objField.value.replace(/(([a-z])*)(([A-Z])*)/g,'') != ''
&& !isBlank(objField.value)){
msg = ALPHACHARONLY.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/nocharonly/g)){
if (eval(objField.value.replace(/(([a-z])*)(([A-Z])*)(\d*)/g,'')) != ''
&& !isBlank(objField.value)){
msg = NOCHARONLY.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/isemail/g)){
if (eval(objField.value.match(/\w@\w+\.\w{2,3}/g)) == null
&& !isBlank(objField.value)){
msg = ISEMAIL.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/comparefield/g)){
var txtFieldObject = eval('"'+frmValidate.match(/comparefield=\w*.\w*.\w*/g)+'"')
txtFieldObject = txtFieldObject.replace(/CompareField=/,'')
if (eval(objField.value) != eval(txtFieldObject+'.value')){
msg = COMPAREFIELD.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/isusername/g)){
if (
(
(objField.value.match(/[aA-zZ|0-9|_|-]+/g)
!= objField.value)
&& !isBlank(objField.value)
)
||
(
(objField.value.length < 4) || (objField.value.length > 30))
){
msg = ISUSERNAME.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/ispassword/g)){
if (
(
(objField.value.match(/[aA-zZ|0-9|_|-]+/g)
!= objField.value)
&& !isBlank(objField.value)
)
||
(
(objField.value).length < 8 || eval(objField.value.length > 20)
)
){
msg = ISPASSWORD.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
}
// ************************************************************************
// *End Only Text, Textarea and Password fields can access the following code
// ************************************************************************
// ************************************************************************
// * Only OPTION fields can access the following code
// ************************************************************************
if (objTextProp.frmFieldType == 'select-multiple' || objTextProp.frmFieldType == 'select-one'){
if (blnErrorFlag == false && frmValidate.match(/required/g)){
var strSelectedValue = '';
var strSelectedLength = 0;
for (var i = 0; i < objField.length; i++) { // Loop through the selected items to create the strSelectedValue
if (objField.options[i].selected){
strSelectedValue = strSelectedValue += objField.options[i].value;
}
}
if (strSelectedValue == ''){
msg = REQUIRED.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/lengthmin=\d*/g)){
var strSelectedLength = 0;
var minlength = eval('"'+frmValidate.match(/lengthmin=\d*/g)+'"');
minlength = parseInt(minlength.match(/\d+/));
for (var i = 0; i < objField.length; i++) { // Loop through the selected items to create the strSelectedValue
if (objField.options[i].selected){
++strSelectedLength;
}
}
if (strSelectedLength < minlength){
msg = LENGTHMIN.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<length>',minlength);
if(minlength == 1){
msg += ".";
} else {
msg += "s.";
}
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/lengthmax=\d*/g)){
var strSelectedLength = 0;
var maxlength = eval('"'+frmValidate.match(/lengthmax=\d*/g)+'"');
maxlength = parseInt(maxlength.match(/\d+/));
for (var i = 0; i < objField.length; i++) { // Loop through the selected items to create the strSelectedValue
if (objField.options[i].selected){
strSelectedLength = strSelectedLength+1;
}
}
if (strSelectedLength > maxlength ){
msg = LENGTHMAX.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<length>',maxlength);
doErrorDetected(msg);
}
}
}
// ************************************************************************
// * End of Only OPTION fields can access the following code
// ************************************************************************
// ************************************************************************
// * Only radio and check box fields can access the following code
// ************************************************************************
if (objTextProp.frmFieldType == 'checked'){
if (blnErrorFlag == false && frmValidate.match(/required/g)){
var strSelectedValue = '';
for (i = 0, j = objField.length; i < j; i++) { // Loop through the selected items to create the strSelectedValue
if (objField[i].checked == true){
strSelectedValue = strSelectedValue += objField[i].value;
}
}
if (strSelectedValue == ''){
msg = REQUIRED.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/lengthmin=\d*/g)){
var strSelectedLength = 0
var minlength = eval('"'+frmValidate.match(/lengthmin=\d*/g)+'"');
minlength = parseInt(minlength.match(/\d+/));
for (i = 0, j = objField.length; i < j; i++) { // Loop through the selected items to create the strSelectedValue
if (objField[i].checked == true){
++strSelectedLength;
}
}
if (strSelectedLength < minlength){
msg = LENGTHMIN.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<length>',minlength);
if(minlength == 1){
msg += ".";
} else {
msg += "s.";
}
doErrorDetected(msg);
}
}
if (blnErrorFlag == false && frmValidate.match(/lengthmax=\d*/g)){
var strSelectedLength = 0
var maxlength = eval('"'+frmValidate.match(/lengthmax=\d*/g)+'"');
maxlength = parseInt(maxlength.match(/\d+/));
for (i = 0, j = objField.length; i < j; i++) { // Loop through the selected items to create the strSelectedValue
if (objField[i].checked == true){
++strSelectedLength;
}
}
if (strSelectedLength > maxlength){
msg = LENGTHMAX.replace('<fieldlabel>',frmFriendlyName.toUpperCase());
msg = msg.replace('<length>',maxlength);
doErrorDetected(msg);
}
}
}
// ************************************************************************
// * End of only radio and check box fields can access the following code
// ************************************************************************
// Begn the return value sent back let the client know the field pass or failed
// the validation
return blnErrorFlag;
// End the return value sent back let the client know the field pass or failed
}
}
function Confirmit(mess) {
var confirmVar=confirm(mess);
return confirmVar;
}
// ************************************************************************
// * A new function added to check for valid dates
// ************************************************************************
function isDate(dateStr) {
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
return false;
}
month = matchArray[1]; // p@rse date into variables
day = matchArray[3];
year = matchArray[5];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn`t have 31 days!")
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day==29 && !isleap)) {
alert("February " + year + " doesn`t have " + day + " days!");
return false;
}
}
return true; // date is valid
}
function isEuroDate(dateStr) {
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
return false;
}
day = matchArray[1]; // p@rse date into variables
month = matchArray[3];
year = matchArray[5];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn`t have 31 days!")
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day==29 && !isleap)) {
alert("February " + year + " doesn`t have " + day + " days!");
return false;
}
}
return true; // date is valid
}
0 Response to "Validation in PHP"
Post a Comment