On 6/14/07, Kevin Murphy <php@xxxxxxxxxxxxxxxxxx> wrote:
I collect phone numbers via a web form that breaks the phone number up into 3 parts (3-digit area, 3-digit prefix, etc). Occasionally, I am having people put in a phone number such as 999-999-9999 or 000-000-0000 or other numbers that are all the same. How would I go about comparing those three fields to see if they are all the same numbers. I can't just exclude it anytime that the numbers all match, for example 444 is a valid area code. It should only fail if all the numbers are exactly the same. 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
Like others have said, there isn't much you can do about this. People are either going to give you their information or not. The only thing you can do is make sure there is a value that could possibly be a phone number for people who might have just forgot to input one. Otherwise you're going to just end up stepping on someone's toes who really means to do what they are doing. 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 example@xxxxxxxxxxx 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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php