
PHP Telephone Number Concealment
The following is a simple script, which blanks out a telephone number before displaying it.
First I use the if (ereg("^\([[:digit:]]{3}\)[[:digit:]]{3}-[[:digit:]]{4}$",$telephone)){ this validates the telephone number in this format (xxx)xxx-xxxx
I then use echo ereg_replace("\([[:digit:]]{3}\)[[:digit:]]{3}-[[:digit:]]{4}$","Your telephone number was (XXX)XXX-XXXX",$telephone); to blank out the telephone number before its displayed.
Example
Please enter a telephone number with the format (333)333-3333
Script Source
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="posted" value="true">
<input type="text" name="number" />
<input type="submit" value="Try it!" />
</form>
<?php
error_reporting(0);
$telephone = $_POST['number'];
if (ereg("^\([[:digit:]]{3}\)[[:digit:]]{3}-[[:digit:]]{4}$",$telephone)){
echo ereg_replace("\([[:digit:]]{3}\)[[:digit:]]{3}-[[:digit:]]{4}$","Your telephone number was (XXX)XXX-XXXX",$telephone);
} else {
echo "Please enter a telephone number with the format (333)333-3333";
}
// Script by www.wizzardweb.co.uk
// Please do not remove this information -- Copyright 2007
?>
Please let me know if this script was helpful to you.