Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Thursday, 18 August 2016

Remove Non numbers in input values in jquery



Remove Non numbers in input values in jquery

if (/\D/g.test(this.value))
{
   
// Filter non-digits from input value.
   
this.value = this.value.replace(/\D/g, '');
}

Tuesday, 1 December 2015

Remove all characters and spaces form string in php

Remove all characters and spaces form string in php


 $string = 'name @123&';
 
echo preg_replace('/[^A-Za-z0-9\-]/', '', $string)

Thursday, 2 July 2015

Upload CSV file in php

Upload CSV file

             $File_Name=$_FILES['upload']['tmp_name'];

                $fp=fopen($File_Name,'r');

                while($data=fgetcsv($fp))
                {
                    $add_data=array('Name'=>$data[0],'No_of_Nights'=>$data[1])

                 }

Wednesday, 11 September 2013

Enable or Disable Text field when check the check box in php

//Enable or Disable Text field when check the check box in php

<html>
<head>
<title>bnr</title>
<script language="JavaScript">
<!--

function enable_text(status)
{
status=!status;
document.f1.other_text.disabled = status;
}
//-->
</script>
</head>
<body onload=enable_text(false);>

<form name=f1 method=post>
<input type="checkbox" name=others onClick="enable_text(this.checked)" >Others
<input type=text name=other_text>
</form>

</body>
</html>

Friday, 23 August 2013

Javascript validations in php using functions

//JavaScript Validations in php using onblur, onkeyup functions


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<script type="text/javascript">
function user()
{
var name=document.form1.name.value;
var namexp=/^[a-zA-Z ]*$/;

if(name=="")
{
document.getElementById("d1").innerHTML="Please Enter Name";
document.form1.name.focus();
return false;
}
else if(!name.match(namexp))
{
document.getElementById("d1").innerHTML="Only letters";
return false;
}

else if(name.length<5)
{document.getElementById("d1").innerHTML="Minimum 5";
document.form1.name.focus();
return false;
}
else
document.getElementById("d1").innerHTML="";

}


function user1()
{
var mobile=document.form1.mobile.value;
var phexp=/^[0-9]+$/;
if(mobile=="")
{
document.getElementById("d2").innerHTML="Please Enter mobile Number";
document.form1.mobile.focus();
return false;
}
else if(!mobile.match(phexp))
{
document.getElementById("d2").innerHTML="Only Numbers";
return false;
}

else if(mobile.length!=10)
{
document.getElementById("d2").innerHTML="Invalid:Only 10 numbers";
return false;
}

else
document.getElementById("d2").innerHTML="";

}
</script>
<form id="form1" name="form1" method="post" action="">
  <table width="1000" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="219">&nbsp;</td>
      <td width="70">&nbsp;</td>
      <td width="158">&nbsp;</td>
      <td width="470">&nbsp;</td>
      <td width="40">&nbsp;</td>
      <td width="43">&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>Name</td>
      <td><input type="text" name="name" id="name" onblur="return user()" onkeyup="return user();" autocomplete="off" /></td>
      <td><div id="d1" style="color:#F00"></div></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>Mobile</td>
      <td><input type="text" name="mobile" id="mobile" onblur="return user1()" onkeyup="return user1()" /></td>
      <td><div id="d2" style="color:#F00"></div></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><input type="submit" name="submit" id="submit" value="Submit" /></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
</body>
</html>

Tuesday, 9 July 2013

Registration Form in PHP using Java Script Validations

// Registration Form in PHP using Java Script Validations

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<style type="text/css">
.regfirm {
font-size: 20px;
color: #0033FF;
}
.star {
color: #F00;
}
</style></head>

<body>
 <script type="text/javascript">
function uservalid()
{
var name=document.form1.name.value;
var namexp=/^[a-zA-Z ]*$/;
var uid=document.form1.uid.value;
var password=document.form1.pass.value;
var pexpnum=/^(?=.*[0-9])/;
var pexpcap=/^(?=.*[A-Z])/;
var pexpsm=/^(?=.*[a-z])/;
var cpass=document.form1.cpass.value;
var dob=document.form1.dob.value;
var phno=document.form1.mobile.value;
var phexp=/^[0-9]+$/;
var email=document.form1.email.value;
var atpos=email.indexOf("@");
var dotpos=email.lastIndexOf(".");
var address=document.form1.addr.value;
if(name=="")
{
alert("Please Enter Your Name");
document.form1.name.focus();
return false;
}
else if(!name.match(namexp))
{
alert("Please Enter Valid Name");
document.form1.name.focus();
return false;
}
else if(uid=="")
{
alert("Please Enter User Id");
document.form1.uid.focus();
return false;
}
else if(uid.length<5)
{
alert("User Id Minimum 5 letters");
document.form1.uid.focus();
return false;
}

else if(password=="")
{
alert("Please Enter Password");
document.form1.pass.focus();
return false;
}
else if(password.length<6)
{
alert("Password must be more than 6 letters");
document.form1.pass.focus();
return false;
}
else if(!password.match(pexpnum))
{
alert("Password contain atleast one Number");
document.form1.pass.focus();
return false;
}
else if(!password.match(pexpcap))
{
alert("Password contain atleast one Capital letter");
document.form1.pass.focus();
return false;
}
else if(!password.match(pexpsm))
{
alert("Password contain atleast one Small letter");
document.form1.pass.focus();
return false;
}
else if(cpass=="")
{
alert("Please Enter Conform Password");
document.form1.cpass.focus();
return false;
}
else if(password!=cpass)
{
alert("Password and Conform password must be same");
document.form1.cpass.focus();
return false;
}
else if(dob=="")
{
alert("Please Enter Date Of Birth");
document.form1.dob.focus();
return false;
}
else if(phno=="")
{
alert("Please Enter Phone no");
document.form1.mobile.focus();
return false;
}
else if(!phno.match(phexp))
{
alert("Enter Valid Phone no");
document.form1.mobile.focus();
return false;
}
else if(phno.length!=10)
{
alert("Enter 10 digit Phone no");
document.form1.mobile.focus();
return false;
}
else if(email=="")
{
alert("Please Enter Email Id");
document.form1.email.focus();
return false;
}
else if(atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length)
{
alert("Enter Valid Email Id EX: abc@d.com");
document.form1.email.focus();
return false;
}
   else if ( ( document.form1.gender[0].checked == false ) && ( document.form1.gender[1].checked == false ) )
   {
        alert ( "Please choose Your Gender" );
        document.form1.gender[0].focus();
        return false;
    }
else if(address=="")
{
alert("Please Enter Your Full Address");
document.form1.addr.focus();
return false;
}


}
</script>

<table width="562" border="0" align="center" vspace="0px">
  <tr>
    <td>
    <form name="form1" id="form1" method="post" action="" onsubmit="return uservalid()"><table width="500" border="0" align="center">
      <tr>
        <td colspan="2" align="center"><span class="regfirm">Registraion Form</span></td>
      </tr>
      <tr>
        <td width="135">Name <label class="star">*</label></td>
        <td width="234" height="35"><input type="text" name="name" id="name" placeholder="Enter Your Full Name" /></td>
      </tr>
      <tr>
        <td>User Id <label class="star">*</label></td>
        <td height="35"><input type="text" name="uid" id="uid" placeholder="Enter Your User Id" /></td>
        </tr>
      <tr>
        <td>Password <label class="star">*</label></td>
        <td height="35"><input type="password" name="pass" id="pass" placeholder="Create New Password" /></td>
        </tr>
      <tr>
        <td>Conform Password <label class="star">*</label></td>
        <td height="35"><input type="password" name="cpass" id="cpass" placeholder="Enter Same Password " /></td>
        </tr>
      <tr>
        <td>Date Of Birth <label class="star">*</label></td>
        <td height="35"><input type="date" name="dob" id="dob" /></td>
        </tr>
      <tr>
        <td>Contact Number <label class="star">*</label></td>
        <td height="35"><input type="text" name="mobile" id="mobile" placeholder="Enter Your Contact Number" /></td>
        </tr>
      <tr>
        <td>Email Id <label class="star">*</label></td>
        <td height="35"><input type="text" name="email" id="email" placeholder="Enter Your Email Id" /></td>
        </tr>
      <tr>
        <td>Gender <label class="star">*</label></td>
        <td><p>
          <label>
            <input type="radio" name="gender" value="male" />
            Male</label>
          <br />
          <label>
            <input type="radio" name="gender" value="female" />
            Female</label>
          <br />
        </p></td>
        </tr>
      <tr>
        <td>Address <label class="star">*</label></td>
        <td><textarea name="addr" id="addr" cols="25" rows="3" placeholder="Enter Your Full Address" style="resize:none"></textarea></td>
        </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
      <tr>
        <td colspan="2"><table width="358" border="0">
          <tr>
            <td width="104">&nbsp;</td>
            <td width="95"><input type="submit" name="submit" id="submit" value="Submit" /></td>
            <td width="103"><input type="reset" name="reset" id="reset" value="Reset" /></td>
            <td width="38">&nbsp;</td>
            </tr>
          </table></td>
      </tr>
      </table>
    </form></td>
  </tr>
  <tr>
  <td height="30" align="center" bgcolor="#3850AF">Copy Rights&copy;Narsi Reddy 2013</td>
  </tr>
</table>
</body>
</html>

Saturday, 29 June 2013

Amstrong in php

<html>
<head>
<title></title>
</head>
<body>
<?php
function amstrong($n,$m,$sum=0,$r)
{
$n=111;
$m=$n;
while($n!=0)
{
$r=$n%10;
$sum=$sum+$r*$r*$r;
$n=$n/10;
}
if($m==$sum)
{
echo "<h1><font color='green'>amatrong</font></h1>";
}
else
{
echo "<h1><font color='red'>not amstrong</font></h1>";
}
}return amstrong($n,$m,$sum,$r);
?>
</body>
</html>

Simple examples in php

<html>
<head><title>example</title>
</head>
<body>
<?php
echo "<b><h1>welcome to bnr</h1></b><br/>";

$a="<h2>welcome to bnr</h2>";
echo $a;
print "<br/>";
$b=2;
echo $b;
echo "<br/>";
print "<br/>";
$c="Welcome";
$d="To";
$e="BNR";
echo $c." ".$d." ".$e;
?>
</body>
</html>

Friday, 28 June 2013

php syntax

PHP Syntax Tags........

<?php    // Open Tag


?>      // Close Tag