Full-service Internet Marketing & Web Development
Recent Posts

Sponsors
![]() |
Check Valid Phone NumberCode Wizard, 12-30-2006 |
Stop those lame users that put "asd;3o4itjui" as their phone number. Useful for e-commerce.
<?
// Number.php
// Check to see if a user input the proper input for a phone number.
// Useful for e-commerce or e-mail scripts.
error_reporting(0); // Error reporting turned off because of bug I get in PHP 4.0.4 that produces an error message if a variable that does not exist is called, you can turn it off if you are using early versions, I recommend keeping it on, the code does work. :)
$num = "($number) $number1-$number2"; // Format used by regular expression.
echo "<table cellspacing=0 cellpadding=0 border=0 height=100% width=100%><tr><td valign=center height=100% width=100%><center><font face=verdana size=1><form action='number.php'>Area Code: ( <input type=text name=number maxlength=3 size=3 style='background-color: #FFFFFF; color: #000000; font-family: Verdana; font-size: 10px; border: 1 solid #000000'> ) 7 Digit Phone Number: <input type=text name=number1 maxlength=3 size=3 style='background-color: FFFFFF; color: #000000; font-family: Verdana; font-size: 10px; border: 1 solid #000000'> - <input type=text name=number2 maxlength=4 size=4 style='background-color: #FFFFFF; color: #000000; font-family: Verdana; font-size: 10px; border: 1 solid #000000'> <input type=submit value='Check!' style='background-color: #FFFFFF; color: #000000; font-family: Verdana; font-size: 10px; border: 1 solid #000000'></form><BR><BR>Valid?: "; // Just some HTML to make the script look pretty. All the HTML <input type=text> tags are required if you change the way the script looks, which I plan on you doing. Just remember to change the variable names is $num if you change them in the <input> fields.
if($number) // Checks whether or not the Check! button has been clicked on, just a little trick of mine. :)
{
if(eregi("^([0-9]{3})[[:space:]][0-9]{3}-[0-9]{4}$", $num)) // Heart of it all. This expression is what checks the validity.
{
echo "$num is valid."; // If the input matches the regular expression, it is valid, thus the script echoing so.
}
else
{
echo "$num is invalid."; // If the input does not match the regular expression, it is invalid, thus the script echoing so.
}
}
echo "</center></td></tr></table>";
// That's All Folks!
// James Wirth a.k.a. orb(it)
?>
|
|
Subscribe Now to receive new posts via Email as soon as they come out.
Comments
Post your comments

