‘web development’ Archives
To check leap year
function IsLeapYear(year) { if ((year%4)==0) { if ((year%100==0) && (year%400)!=0) { return false; } else { return true; } } else { return false; } }
URL validation
function checkURL(url) { var theurl=url; var tomatch= /^(http?:\/\/|ftp:\/\/)(www\.)?+\.(com|org|net|mil|edu|ca|co.uk|co.in|com.au|ac.in|gov|gov.in)(\/)?/; if (tomatch.test(theurl)) { return true; } else { return false; } }
validate email address
function echeck(str) { var at="@" var dot="." var lat=str.indexOf(at) var lstr=str.length var ldot=str.indexOf(dot) if (str.indexOf(at)==-1){ return false } if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ return false } if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ return false } if [...]
to check alphanumeric character
function isAlphaNumeric(valueToTest) { var myRegxp = /^+$/; if(myRegxp.test(valueToTest) == 1) { return true; } else { return false; } }
function to restrict text area character
function checkTextLength(obj,restrictLength,truncFlag) { if(obj.value.length>restrictLength){ if(truncFlag) obj.disabled = true; alert("Text should not be more than " + restrictLength + " characters"); if(truncFlag) obj.disabled = false; obj.focus(); if(truncFlag) obj.value = obj.value.substring(0,restrictLength); return false; }else{ return [...]
trim function in javascript
function trim(sString) { sTrimmedString = ""; if (sString != "") { var iStart = 0; var iEnd = sString.length - 1; var sWhitespace = " \t\f\n\r"; while (sWhitespace.indexOf(sString.charAt(iStart)) != -1) { iStart++; if (iStart > iEnd) break; } // If the string not just whitespace if (iStart <= iEnd) { while [...]
validate credit card number using javascript
function isValidCreditCard(cardNo) { var str=cardNo; var digitsOnly = str.replace(/ /g,'');//replace unwanted space var sum = 0; var digit = 0; var addend = 0; var timesTwo = false; var i; for(i = digitsOnly.length-1;i >= 0; i--) { digit = parseInt(digitsOnly.substring(i,i+1)); if (timesTwo) { addend = digit * 2; if (addend > 9) { addend -= [...]
How to parse a html document and replace the tag with their corresponding value
<?php class parseHTML { /** * HTML Form Parser * * @package HtmlFormParser * @version $Id 1.0 * @author Vinod Ram *$html_data is the content of html file that you have to parse *$_POST is the array containing the value that is to replaced with * @copyright 2008 vinodram */ public function parseForms($html_data) { $allowedChar = [...]
Calculate number of days,hours, minute, seconds passed from todays date to some past date
<?php function get_time_differenceFromToday($fromDate) { $uts = strtotime( $fromDate );//date format YYYY-MM-DD HH:MM:SS $uts = time();//unix timestamp //strtotime( $end ) if( $uts!==-1 && $uts!==-1 ) { if( $uts >= $uts ) { $diff = $uts - $uts; if($diff > 604800) { return date("m-d-Y [...]
Latest music . videos and songs
PHP Manual