Skip to main content
boloco
Known Participant
October 27, 2009
Question

telephone formating

  • October 27, 2009
  • 1 reply
  • 663 views

Hi there,

can anybody tell me how or where to find a php telephone formating script, preferably from Dreamweaver exchange? I couldn't find any.

Thanks!

This topic has been closed for replies.

1 reply

jon8
Inspiring
October 27, 2009

$phone = $_POST['phone'];

$phone = preg_replace('/[^0-9]/', '', $phone); # remove non-numbers

if (preg_match('/^1?[0-9]{10}$/', $phone)) {
echo 'Valid'; #or do whatever else you want it to do
}

I thought spry had a form validation criteria for a text field for numbers?  guess not.

DwFAQ
Participating Frequently
October 27, 2009
I thought spry had a form validation criteria for a text field for numbers?

Yes spry does have telephone syntax validation but you may not know that users can circumvent the validation simply by disabling javascript on their browser. FYI server side validation can not be circumvented.

I thought spry had a forum for asking about validation criteria for a text field for numbers.

FYI this is the Dreamweaver Application Development forum, not the spry forum

jon8
Inspiring
October 27, 2009

i'm sure this user isn't building a mission critical application, and although there are some people that may turn off javascript, javascript is a common practice used to validate forms.  You know this, but you just like to cause problems and make yourself feel smart.  Adobe provides spry validation in Dreamweaver for a reason.  This is a Dreamweaver forum - it's important to remember your audience when providing advice.  I did provide an alternative php version so I think this topic has been covered.  Thank you for adding your input.