Validating phone numbers in php need a dating site

Posted by / 01-Jun-2020 17:15

Validating phone numbers in php

Several months ago, when I was first getting familiar with regular expression, I made a post talking about PHP form validation for phone numbers and email addresses.

A couple of days ago, I revisited that post and realized how inefficient my function actually was.

So, the pattern matches certain elements in the phone number and separates them.

You can now take each of these elements and format the number as you wish so that all the numbers in the database will follow the same pattern.

Wrap this up in a reusable function, and you have something in your PHP toolkit that can be used over and over again with ease.

Follow me as I take a look at validating user-entered data in this first installment of what I hope to be a continuing series.

It’s best to use some proper PHP tools to validate your data and make sure it’s in a format your application can read before passing it along to other places.

Likewise, you could have a free form field – rather than three separate fields – on a Web page for users to enter a phone number.

This code could validate that number and parse it for your application to use.

validating phone numbers in php-21validating phone numbers in php-77validating phone numbers in php-73

Consider POSIX extended regular expressions the weaker cousin of PCRE (I’ll likely be flamed for this).

One thought on “validating phone numbers in php”