Somnething like this?
//remove all non-digits
$home = preg_replace('/[^\d]/', '', $_POST['home_phone']);
//if it's 10 digits
if(preg_match('/\d{10}/')) {
$home = preg_replace('/(\d{3})(\d{3})(\d{4})/', '\1-\2-\3', $home);
}
On Sat, 17 Jul 2004 12:44:46 -0400, Vincent Jordan
<[EMAIL PROTECTED]> wrote:
> I have a form with a field for a telephone number. I would like to
> either apply some kind of formatting to force format of XXX-XXX-XXXX or
> rewrite after submit to insert - in 3 and 5 (or 6).
> Here is what I have for code:
>
> --Form-
> <td>Home Phone:</td>
> <td><input type="text" name="home_phone" id="home_phone"
> size="15" tabindex="8" /></td>
>
> handler.php
> $home = $_POST['home_phone'
>
> I have tried str_replace() however im not using it correctly or it is
> not the correct string to use for this
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> !DSPAM:40f9556c159931176717192!
>
>
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php