Just answering some of your questions, my regex should check most emails. What traq posted is the basic framework for checking phone numbers. Here is an example of one that will check phone numbers. In particular it checks US phone numbers and puts it into the format you mentioned, if it is a US phone number that is. I got it from php.net and you can read more about it here.
Detect and reformat phone numbers:
PHP Code:
<?php
$phoneNumber="337-333-3443";
$regex = '/^(?:1(?:[. -])?)?(?:\((?=\d{3}\)))?([2-9]\d{2})'
.'(?:(?<=\(\d{3})\))? ?(?:(?<=\d{3})[.-])?([2-9]\d{2})'
.'[. -]?(\d{4})(?: (?i:ext)\.? ?(\d{1,5}))?$/';
if (preg_match($regex, $phoneNumber))
{$formatted = preg_replace($regex, '$1-$2-$3', $phoneNumber);
echo "$formatted";}
else echo "NOT A MATCH";
?>
You can write the info into a text file, but depending on your needs it is usually better to store the data into a database. Sending confirmation emails is not something I know how to do.
What do you mean by a confirmation page? Do you mean that you want to submit the user submitted data to another page and if the submitted data is not valid then go back to the previous page? I am also curious what you mean by an external file. Do you mean like an 'include' file? That might not be a bad idea, but not necessary. It is mostly a way to make managing code easier and quicker.
Well, at least we now have a regex to detect emails and another for US phone numbers
Bookmarks