Archive for December 19th, 2007

validate the number in numeric format

Wednesday, December 19th, 2007

<?php
function PhoneCheck($number)
{
return preg_match(”/^[(\[]?\d{3}[)-\.\] ]*\d{3}[-\. ]?\d{4}$/”, $number, $scrap);
}
?>

is one way…personally i save only the numbers and throw the rest away..makes it simpler and you can always change the display code to format a number for a particular use. 

$phone = preg_replace(”[^0-9]”,”",$_POST[’phone’]);

Posted by Suresh B

How do I go back in the browser in PHP?

Wednesday, December 19th, 2007

You can use javascript to back a page: history.go(-1)

Eg:

Code:
<a href=”#” onclick=”history.go(-1)”>Back</a>

Or you can use PHP code to determine which page they came from and create link like:

Code:
<a href=”<?=$_SERVER[’HTTP_REFERER’]?>”>Back</a>

Posted by Suresh B