All the processes I've come up with seem to be rather convoluted. Is
there a simple way to test for this?
--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada College
www.wnc.edu
775-445-3326
<?php
$number = $field1.$field2.$field3;
$digit = (int)substr( $number, 0, 1 );
if( ereg( '^'.$digit.'+$', $number ) )
{
echo 'All the same :/';
}
?>
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
Whilst there are several ways to do this, it's not going to make someone
entering dummy data give you their real phone number. They'll just enter
another one that bypasses your check, e.g. 111-222-3333 or 321-321-4321.
I'd also caution about forcing any specific format on telephone numbers. I'm
in the UK and our phone numbers are in the format xxxx-xxx-xxxx,
xxx-xxxx-xxxx or xxxxx-xxxxxx. This would not work with your form. If people
are happy to give you their number, let them type it how it is. It could
even include other characters, e.g. +44 (0)1234 567890 ex 324
Edward
My suggestion is that we require the United Kingdom and other
countries around the world to conform to our standards of telephone
numbers. After all, isn't that what we do in America; change the
world to meet our expectations or choose to shun them for not doing
so?
Nevermind.... that would go far beyond list topics and waaaay too
far into the realm of political dissent.
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
The code that Robert supplied seems to work just great. Thanks.
--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada College
www.wnc.edu
775-445-3326
If you really need to validate the phone number then put a notice up
saying US phone numbers only and give a very specific format that they
must adhere to. This isn't really a good thing though seeing as the
web is a global playground, but maybe you have your reasons.
Now this mindset doesn't transition to other values. If you are
expecting someones age and have the field Age (eg. 35) then you can
check that with ctype_digit() and redisplay the form to them if the
value does not pass.
Another example is that on some forms I make email addresses are
required so we can send them their order confirmation. I use a simple
regex with a hostname lookup to see if the domain exists. Even with
all that the user can always type exa...@example.com and it would
pass perfectly.
Just as an aside, validate data. Don't try to sanitize into something
you want. What I mean is if you are asking for a credit card number
don't do a preg_replace to strip out non-numbers. Instead do a
preg_match() or ctype_digit() on numbers only and if it doesn't match
exactly what you want, spit it back to the user and tell them to fix
it.