Validate a Phone Number

?Regular expression?which checks or validates a phone number.

$format1 = “/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i”;
// 1- 555- 555- 5555
// or 555- 555- 5555

preg_match(‘/^[+]?([0-9]{1,15})?([\.\-\s0-9]{1,15})$/’, $_REQUEST[‘telephone’])

//+9382938209329

//98979 9090 9089

//929-99090 909

 

 

Left side multi category product search


############################# Showing feature on left hand side as in fabric site #######################
<? if(count($_SESSION['feature']) > 0){ ?>
<div style="width:100px;height:20px;border:0px solid red;color: #000;font-size: 16px;font-family: Candara;font-weight: bold;cursor:pointer;" id="clear_search">Clear Search X</div>
<? } ?>
<div class="feature_products_container">
<? $sql_fabric_feature_name = "SELECT * FROM fabric_feature_name ORDER BY id";
$rs_fabric_feature_name = mysql_query($sql_fabric_feature_name);
if(mysql_num_rows($rs_fabric_feature_name) > 0){
while($data = mysql_fetch_assoc($rs_fabric_feature_name)){
$feature_name = $data['name'];
$feature_name_id = $data['id'];
?>
<div class="feature_heading">
<?=$feature_name;?>
</div>
<div>
<?
$sql_fabric_feature_value = "SELECT * FROM fabric_feature_value WHERE feature_name_id = $feature_name_id ORDER BY id";
$rs_fabric_feature_value = mysql_query($sql_fabric_feature_value);
if(mysql_num_rows($rs_fabric_feature_value) > 0){
while($data1 = mysql_fetch_assoc($rs_fabric_feature_value)){
if(count($_SESSION['feature']) == 0){
unset($_SESSION['feature']);
}
$feature_value = $data1['value'];
$feature_value_id = $data1['id'];
//$feature = array($feature_name_id=>$data1['id']);
$feature = $feature_name_id."-".$feature_value_id;
if(isset($_SESSION['feature'])){
$key = array_search($feature,$_SESSION['feature']);
$checked = ($key !== false) ? "checked" : "";
}else{
$checked = "";
}
?>
<div class='feature_value'>
<input type='checkbox' <?=$checked;?> class='feature_class' name='feature[<?=$feature_name_id;?>]' alt='<?=$feature_name_id;?>' value='<?=$data1['id'];?>' />
<?=$feature_value;?>
</div>
<? } } ?>
</div>
<? } } ?>
</div>
############################################ Calling ajax on selecting left hand site feature ##################
<script type="text/javascript">
$(document).ready(function(){
$('#clear_search').live("click",function(){
$.ajax({
type: "POST",
url: "ajax/ajax_actions.php?action=clear_search",
success: function() {
window.location.reload();
}
});
});

$('.feature_class').live("click",function(){

var feature_name_id = $(this).attr('alt');
var feature_value_id = $(this).val();
var check_box_value = ($(this).is(':checked')) ? 1 : 0;
var form_data = {'feature_name_id':feature_name_id,'feature_value_id':feature_value_id,'check_box_value':check_box_value};
$.ajax({
type: "POST",
url: "ajax/ajax_actions.php?action=fabric_feature_product",
data: form_data,
success: function() {
window.location.reload();
//$('#sale_clock div.clock').html(html);
}
});
});
});
</script>
########################################## Ajax file code ################################################
if(isset($_REQUEST['action']) && $_REQUEST['action'] == "fabric_feature_product"){

$feature_name_id = $_REQUEST['feature_name_id'];
$feature_value_id = $_REQUEST['feature_value_id'];
$check_box_value = $_REQUEST['check_box_value'];
$feature = $feature_name_id."-".$feature_value_id;
if(!isset($_SESSION['feature'])){
$_SESSION['feature'] = array();
}
if($check_box_value == 1){
array_push($_SESSION['feature'],$feature);
}else{
$key = array_search($feature,$_SESSION['feature']);
unset($_SESSION['feature'][$key]);
}
//echo "<pre>";
//print_r($_SESSION['feature']);
die;
}elseif(isset($_REQUEST['action']) && $_REQUEST['action'] == "clear_search"){
unset($_SESSION['feature']);
die;
}
##################################### After searching according to above products search ###################################################
if(isset($_SESSION['feature'])){
sort($_SESSION['feature']);
$feature_count = count($_SESSION['feature']);
//echo "<pre>";
//print_r($_SESSION['feature']);
$feature_name_id_flag = "";
$arr1 = array();
$arr2 = array();
$intersect_result = array();
foreach($_SESSION['feature'] as $feature){
$feature_array = explode("-",$feature);
$feature_name_id = $feature_array[0];
$feature_value_id = $feature_array[1];

if($feature_name_id_flag == $feature_name_id){
$sql_intersect = "SELECT distinct product_id FROM fabric_feature_mapping as ffm WHERE ffm.feature_name_id=$feature_name_id AND ffm.feature_value_id=$feature_value_id";
$result_intersect = mysql_query($sql_intersect);
while($row_intersect = mysql_fetch_assoc($result_intersect)){
array_push($arr1,$row_intersect['product_id']);
}
}else{
$intersect_result = intersect_function($arr1,$intersect_result);
$arr1 = array();
//print_r($intersect_result);
$sql_intersect = "SELECT distinct product_id FROM fabric_feature_mapping as ffm WHERE ffm.feature_name_id=$feature_name_id AND ffm.feature_value_id=$feature_value_id";
$result_intersect = mysql_query($sql_intersect);
while($row_intersect = mysql_fetch_assoc($result_intersect)){
array_push($arr1,$row_intersect['product_id']);
}
$feature_name_id_flag = $feature_name_id;

}
}
$intersect_result = intersect_function($arr1,$intersect_result);
//print_r($intersect_result);
if(count($intersect_result)>0){
$common_records = implode(",",$intersect_result);
}
$sql = "SELECT DISTINCT gp.productID,gp.productMainImage,gp.productRRP,gp.productPrice,gp.productName,gp.productCategoryID,gp.productDescription,gp.productManufacturerID FROM `gurProducts` as gp
WHERE gp.productID IN ($common_records ) AND (productCategoryID='".$result['id']."' OR productCategory2ID='".$result['id']."' OR productCategory3ID='".$result['id']."')
AND gp.productAvailable='1' ORDER BY gp.productPrice + 0 ASC";
}else{
$sql = "SELECT DISTINCT productID,productMainImage,productRRP,productPrice,productName,productCategoryID,productDescription,productManufacturerID FROM `gurProducts` WHERE (productCategoryID='".$result['id']."' OR productCategory2ID='".$result['id']."' OR productCategory3ID='".$result['id']."') AND productAvailable='1' ORDER BY productPrice + 0 ASC";
}
########################### intersect function #############################################
function intersect_function($arr1,$intersect_result){
if(count($intersect_result) > 0){
$intersect_result = array_intersect($intersect_result,$arr1);
return $intersect_result;
}else{
$intersect_result = $arr1;
return $intersect_result;
}
}

Age Validation in JavaScipt

//age handling
var dob = $(“#date_of_birth”).val();
var arr = dob.split(‘-‘);

var day = arr[0];
var month = arr[1];
var year = arr[2];
var age = 18; //allowed age
var mydate = new Date();
mydate.setFullYear(year, month-1, day);
var currdate = new Date();
currdate.setFullYear(currdate.getFullYear() – age);

if ((currdate – mydate) < 0){
alert(“Your age should be greater than 18 years for registration “);
is_error = true;
return false;
}
//age handling

Append new row in table

Append new row in table after an ID


var tr = '<tr style="display:none:width:100%" >';
tr += '<td align="left" bgcolor="#FFFFFF" class="product_name">'+sku+'</td>';
tr += '<td align="left" bgcolor="#FFFFFF">'+productname+'</td>';
tr += '<td align="left" bgcolor="#FFFFFF"><input class="ed_pro_input quantity" style="width:100px" type="text" id="quantity" alt="'+productId+'" name="quantity['+productId+']" value="1"></td>';
tr += '<td align="left" bgcolor="#FFFFFF"><input class="ed_pro_input cost" style="width:100px" type="text" id="cost" alt="'+productId+'" name="cost['+productId+']" value="'+cost+'"></td>';
tr += '<td align="center" bgcolor="#FFFFFF"><span class="delete" onclick=" javascript:return confirm(\'Are you sure! You want to delete\');"><img src="../images/del.gif" border="0" /> </span></td>';
tr += '</tr>';
$(tr).insertBefore('#last_tr');