function scrollToBottomOfdiv(divID) {
mydiv = document.getElementById(divID);
mydiv.scrollTop = mydiv.scrollHeight;
}
Filed under: Javascript | Tagged: automatic scroll, scroll div, scroll down | 2 Comments »
function scrollToBottomOfdiv(divID) {
mydiv = document.getElementById(divID);
mydiv.scrollTop = mydiv.scrollHeight;
}
Filed under: Javascript | Tagged: automatic scroll, scroll div, scroll down | 2 Comments »
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=Paris%20Hilton" // sendRequest // note how referer is set manually $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, "http://www.yousite.com"); $body = curl_exec($ch); curl_close($ch); // following function json_decode is ready avaialable in php 5 > $json = json_decode($body);
Filed under: Php | Tagged: custom search code, google search, php search | Leave a Comment »
For some good reasons some server hide php errors , still you want to display it for debugging purpose then use following simple two lines of code in a page where you want to display error
error_reporting(E_ALL);
ini_set(“display_errors”,”1″);
Filed under: Php | Tagged: error report, ini_set, show error | Leave a Comment »
<script type=”text/javascript”>
function checkAll(fieldName, val)
{
var chkarr = document.getElementsByName(fieldName);
for(r=0;r<chkarr.length;r++)
{
if (val == true)
chkarr[r].checked = true;
else
chkarr[r].checked = false;
}
}
</script>
Check All
Mango
Banana
Apple
Filed under: Javascript | Tagged: cheking all checkbox, select all checkbox | Leave a Comment »
validate date format e.g. 12-2-2004,12-11-08
function validateDate()
{
obj=//name of your object
msg=//your mesage comes here
var validNum = /^([0-9]{1,2})-([0-9]{1,2})-([0-9]{2,4})$/;
if (validNum.test(obj.value) == false)
{
alert(msg);
obj.focus();
//obj.select();
return false;
}
return true;
}
Filed under: Javascript | Tagged: date check, date validation | Leave a Comment »
function validateUrl()
{
obj=document.getElementById(‘txtUrl’);
msg=”Enter valid url”;
var urlStr = /^\http\:\/\/[a-zA-Z]{3,}\.[a-zA-Z0-9]{2,}
(\.[a-zA-Z]{2,3}|\.[a-zA-Z]{2,3}\.[a-zA-Z]{2})$/;
if (urlStr.test(obj.value) == false)
{
alert(msg);
obj.focus();
obj.select();
return false;
}
return true;
}
Filed under: Javascript | Tagged: javascript validation, url validation | Leave a Comment »
function validateEmail()
{
//name of email input field
obj=document.getElementById(‘txtEmail’);
msg=”Please enter valid email address”;
var emailStr = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z]
[a-zA-Z\.]*[a-zA-Z]$/;
if (emailStr.test(obj.value) == false)
{
alert(msg);
obj.focus();
obj.select();
return false;
}
return true;
}
Filed under: Javascript | Tagged: email validation js, form validation | 2 Comments »
To avoid the cross side scripting or make site safe from hacker attacks one need to perform data validation before allowed data insertion into database . We can achieve this using php preg_match which check data format to see whether it is in valid state or not. The following code snippet is standard validation example
function isHackerSafeUsername($Subject)
{
if( preg_match(“/^[a-zA-Z][\w\._]*[a-zA-Z0-9]$/”,$Subject)) return true;
else return false;
}
function isHackerSafePassword($Subject)
{
if( preg_match(“/[^a-zA-Z0-9@._'-]/”,$Subject)) return false;
else return true;
}
function isHackerSafeName($Subject)
{
if( preg_match(“/^[a-zA-Z]{1,}$/”,$Subject)) return true;
else return false;
}
function isHackerSafeEmail($Subject)
{
if( preg_match(“/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*
[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]/”,$Subject)) return true;
else return false;
}
function isHackerSafeLan($Subject)
{
if( preg_match(“/^[a-zA-Z]{1}$/”,$Subject)) return true;
else return false;
}
function isHackerSafeNumber($Subject)
{
if( preg_match(“/^[0-9]{1,15}$/”,$Subject)) return true;
else return false;
}
function isHackerSafeAddress($Subject)
{
if( preg_match(“/^[a-zA-Z0-9\s,]{1,}$/”,$Subject)) return true;
else return false;
}
function isHackerSafeTitle($Subject)
{
if( preg_match(“/^[a-zA-Z0-9\s,]{1,}$/”,$Subject)) return true;
else return false;
}
function isHackerSafeCityState($Subject)
{
if( preg_match(“/^[a-zA-Z\s]{1,}$/”,$Subject)) return true;
else return false;
}
function isHackerSafeAnswer($Subject)
{
if( preg_match(“/^[a-zA-Z0-9\s]{1,}$/”,$Subject)) return true;
else return false;
}
function isHackerSafeQuestion($Subject)
{
if( preg_match(“/^[a-zA-Z]{1,}$/”,$Subject)) return true;
else return false;
}
?>
Filed under: Php | Tagged: hackersafe, Php, preg_match | Leave a Comment »
function validatePhone(obj,msg)
{
var validNum =/^[\(]?(\d{0,3})[\)]?[\s]?[\-]?(\d{3})[\s]?[\-]?(\d{4})[\s]?[x]?(\d*)$/;
if (validNum.test(obj.value) == false)
{
alert(msg);
obj.focus();
obj.select();
return false;
}
return true;
}
Filed under: Javascript | Tagged: Javascript, regular expression | Leave a Comment »
Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!
Filed under: Uncategorized | Leave a Comment »