Simple phone validation for Restaurant Reservations

My Restaurant Reservations plugin does not require a phone number. Your online visitors might not want or ever need to give their phone number, so I left it optional to encourage more reservations.

But some restaurants might want to ask for a phone number. Maybe you make follow-up or reminder phone calls. Or maybe you just want to make sure you have a way to get in touch with them if they never show.

I’ve written a micro-plugin you can download and activate on your site that will required a phone number and perform some basic validation to see if it looks like a valid phone number.

To use this, download the file onto your computer, then upload the simple-phone-validation-for-rtb.php file to your website’s /wp-content/plugins/ directory. Once the file is there, you’ll be able to activate it by going to the Plugins page in your WordPress admin area. Find the plugin titled, Simple phone validation for Restaurant Reservations and activate it.

What does it do?

When a booking is received, it makes sure that a phone number has been entered. Then it checks to see if the phone number contains at least 5, but no more than 50, characters including numbers, spaces, dashes, periods and parentheses.

That’s a pretty wide range, but I kept it as open as possible because phone numbers are written differently in different countries. If you know valid phone numbers in your area will always be 8 numbers, you can easily change this. Find this line in the file:

preg_match( '/(\d[\s-()\.]*){5,50}\d/', $booking->phone, $matches );

Change the 5,50 part to any range you want. If you want it to be 8-10 characters (including spaces, dashes, periods and parentheses), you’d change it to:

preg_match( '/(\d[\s-()\.]*){8,10}\d/', $booking->phone, $matches );

Be careful, though. You don’t want to make it so strict that a potential diner gets frustrated. Some people write numbers with parentheses, some with spaces, some with dashes. Some people use full area codes. Some people just use local numbers. Make sure you’re not limiting it too much.

The simple validation is good enough to catch most mistakes, when the person making the reservation just forgot to enter their phone number or wrote their email address in the phone field by accident. It’s always a good idea to be generous when validating their phone number so that they don’t have to play a guessing game of how you expect it to be formatted.

Great. Now I want to…

My Gist account includes tons of little snippets which extend and modify my plugins and themes in useful ways. Take a look through the whole library if you’re looking for basic email validation, how to redirect after a successful reservation submission, modify options in the settings, customize the form and more.

Fair warning though, you’ll need to know how to upload and manage your PHP plugin files to use them properly.

Want more great tips like this? Follow me on Twitter or sign up for my mailing list.

Call to action box goes here
Need a Plugin to Improve Your Site?
Browse Plugins Now
🍽️ How to Manage Restaurant Bookings from Your Phone or Tablet Using the Five Star Restaurant Manager App
🍽️ How to Manage Restaurant Bookings from Your Phone or Tablet Using the Five Star Restaurant Manager App

Managing restaurant reservations is one of the most time-sensitive parts of running a busy service. This week, we are highlighting an update that makes this even easier: the newest enhancements to the Five Star Restaurant Manager mobile app, now featuring colour-coded booking statuses for instant clarity at a glance. If you use our Restaurant Reservations…

🎉New Year, New Affiliate Website: How AFFI.AI Can Transform Your Content
🎉New Year, New Affiliate Website: How AFFI.AI Can Transform Your Content

The new year is the perfect time to rethink how your website earns revenue. If you run or plan to start an affiliate website, AFFI.AI, a sister company of Five Star Plugins, can help you transform your content into a revenue-generating engine. Visually Engaging Affiliate LinksInstead of relying on plain text links, AFFI.AI allows you…

🧠The Pros and Cons of Using Caching on Your WordPress Site
🧠The Pros and Cons of Using Caching on Your WordPress Site

Caching is one of the most effective tools to speed up your WordPress site, but it’s also one of the easiest to misconfigure. When used wisely, caching can dramatically improve your site’s load times, reduce server load, and create a better customer experience — especially during high-traffic periods like the holidays. However, if your site…

Discover More Posts
Browse Plugins Now