How to make Yorkshire puddings

yorkshire-pudding-recipe-and-technique

How to make great Yorkshire puddings and get them right every time.

Yorkshire puddings are a simple baked batter mix with a soft and fluffy inside and a lovely crispy outer.

There are a vast number of recipes online with suggestions for how to make Yorkshire pudding.  Some of the recipes are simple; some are way too complicated.  Over the years I’ve been cooking and having tried dozens of recipe tweaks, it is now clear that the perfect pudding comes from the baking, more than the mixture.

We should get a little bit of terminology cleared up here as well.  The individual little puds that you see in the picture are popovers.  Yorkshire pudding – if you’re getting funny over the wording – is the result of cooking the same batter, but in one large pan.

Either way, Yorkshire pud is yummy with a beef dinner, so let’s crack on.

Ingredients:

  • 140g plain flour
  • 200ml milk
  • 4 eggs (medium-largish)
  • Oil
  • Salt & Pepper

Method:

  1. Take a 12 hole muffin tin and add a drop of oil into each hole.
  2. Put your tin into the cold oven and turn it on, then heat your oven to 210C (fan) / 220C (regular) / Gas 8.  I find this a good way of making sure the pan and oil are super hot when you come to pour the batter mix into it.  A cold tin ensures a soggy pudding.  The oil should be just smoking when you get the tin out to add the batter.
  3. While the oven and tin are heating, add your eggs to the flour and beat until it forms a thick paste.  I find an electric beater always excels for this.
  4. Slowly add the milk to the egg/flour mix, still beating as you do.  You’re looking for a lump-free, beautifully smooth liquid that is similar to the consistency of the sauce you find in Heinze baked beans (which is probably a crap analogy, but it’s all I can think of).
  5. Season the batter with salt & pepper.
  6. When the oven is up to temperature, take the tin out and pour enough liquid in to fill each of the holes.  Do this quickly and evenly (don’t worry about spilling a bit).  You are aiming to have to tin out of the oven for as little time a humanly possible.
  7. Bake in the oven for 20-25 minutes, or until golden brown all over.  You will see them rise up and then change colour as they cook.
  8. Remove and eat immediately.

 

A few notes and tips for perfect Yorkshire puddings:

  • Keep the pan as hot as you possibly can at every stage of the cooking.
  • Ensure your batter is lump free.
  • DO NOT OPEN THE OVEN DOOR at any point of the cooking.  The puddings rely on having a hard outer shell to keep them in shape.  If you open the oven door before this outer shell has formed, you will see them deflate in front of your eyes to a sorry looking squidge.  The Yorkshire puddings will NEVER recover from this.
  • You can make these Yorkshire puddings ahead of the meal, to free the oven up for the other things.  As soon as you take them out of the oven, place them on a wire rack to let them cool down, which stops them sweating in the pan and going soft on the bottom.  They’ll stay crunchy on the wire rack for a couple of hours.  If you need to leave them longer than that before eating, put them in a sealed tub to avoid going soft.  You can pop the Yorkshire puddings back in the oven for a few minutes to warm them up while plating up the rest of the dinner.
  • Once the Yorkshire puddings have cooled, you can freeze for up to 2-3 months.

I keep forgetting to mention this: If you need to have a look at a conversion chart, there are some common conversions here.

Share this post:
read more

Create a character countdown for text inputs and textarea’s using jQuery

I think it may have been Twitter that first pioneered the use of the text character countdown years ago.  I could be wrong, maybe they just popularised it, but either way, it is a convenient way of keeping user inputs to a length that is acceptable to your site.

I’m not sure that this is the place to mention it, but I do still find myself writing shorter tweets, despite the limit raise a while ago.

There are going to be three main parts to this:

  • Create an HTML form that needs the input characters kept in check.
  • Write some jQuery code to keep an eye on what is happening when the user’s types.
  • Style a little blank <span> underneath the input to show the user how they are getting on.

For those of you that read regularly, you will know I am a big Bootstrap fan (hark the Twitter reference again), so the form has some Bootstrap elements to it.  This form will work just as well without the BS references.

Create the input:

<label for="myInput"><strong>My Limited Input:</strong></label>
<input class="form-control" type="text" id="myInput" maxlength="50">
<span id="showCountdown" class=limits"></span>

I’ve used the HTML “maxlength” in the above snippet so that the browser automatically restricts any more inputs at that point.  The HTML “maxlength” has nothing to do with the character countdown.  “maxlength” is universally accepted on most browsers except for the ancient, so you shouldn’t run into many [if any] compatibility problems.

Just for curiosities sake, the default value for maxlength is 524288.

Next, we need to add some jQuery to do the counting and append the <span> underneath the input:

$('#myInput').on("keyup change", function ()) {

  const max = 50;
  const len = $(this).val().length;

  if (len >= max) {
    $('#showCountdown').text("No more room ...");
  } else {

    const char = max - len;
    $('#showCountdown').text(char + ' characters remaining');
  }
});

So what’s happening here?

The browser is looking for either a keyup event or a change event occurring in the input.  Change is handy because, in the majority of cases, the will also catch the user if they try and paste something into the box.  When the event is detected, it counts the length of the string inside the input.  It then compares it to the max variable we’ve included and deducts one from the other.

After evaluating whether the length of the input is smaller (by x number) or equal to the max value, it adds an appropriate message into the empty span underneath the box.

Now a little styling:

<style>
#showCountdown {
  font-size: 12px;
  color: #3399ff
}
</style>

You can style this in any way you wish.

Below is an example of this text input in action on a site I’m working on at the moment,  Although I think I used dodgerblue as the colour:

 

 

Share this post:
read more

How to show your latest blog posts on a non-WordPress page

wordpress-blog-header-fluffed-vision

Quite often on a website, there is a need to show your WordPress blog posts outside of the WordPress installation.  You may already have an HTML / PHP site, and you have decided to add a blog page, but want to show some of the posts on the front page (for example).  Luckily, WordPress makes this process as easy as adding a few lines of code to your pages.

You will need a little bit of familiarity with PHP, but realistically, anybody should be able to do it.

There are two things to do:

First, you need to tell your non-Wordpress page that you are going to be extracting information about your posts. So, at the top of the page add the following:

<?php 
  define('WP_USE_THEMES', false);
  require('/wp-load.php');
  query_posts('showposts=4');
?>

Let’s break this down a bit.

The first line tells WordPress that it won’t be needing to use any of its themes.  We are adding the posts to a page that we will assume is already using a stylesheet of its own, so we need the extracted WordPress information to blend in accordingly.

The “require” line will need to be relative to your wp-load.php, so if you have added your blog in the default WordPress directory, this line may end up as:

// If it's in a directory called "wordpress"

require('wordpress/wp-load.php');

// If you need to backtrack to server root to get to you sub-folder

require('../wordpress/wp-load.php');

The exact structure of this line is individual web server and code dependent so will need to be adjusted to suit your exact requirements.

The second line is pretty self-explanatory, it is telling the page to use the WordPress loader.  The loader is required whenever you call anything from WordPress, be it posts, pages, categories etc.

The third line is what we want to extract from the WordPress database.  In this case, we are pulling the lastest four posts.

Following this, we will need to display the posts on the page.  We do this using the standard WordPress API in the form of WordPress hooks.

So:

<?php while (have_posts()): the_post(); ?>

  <h4><?php the_title(); ?></h4>

  <?php the_excerpt(); ?>

  <p><a target="_blank" href="<?php the_permalink(); ?>">Read more...</a></p>

<?php endwhile; ?>

 

That’s it!

The first and last lines tell the page to show posts if there are posts available.  From there, it is just a list of standard WordPress hooks, which on the whole of quite explanatory.  While we are looping through four posts, for each of them, show the post’s title, the excerpt from the post – which can be adjusted in the WordPress admin panel – then add a link to read more.  This link will take the user to the main blog page.

Want to show the full post and not an excerpt from it? No problem.  Just replace “the_excerpt” with “the_content”.

Want to add the posts featured image as well?  No problem, include:

<?php
  if ( has_post_thumbnail() ) {
      the_post_thumbnail();
  }
?>

Here are some working examples:

An example snippet that would show the title of the post, along with the featured image and an extract of the content:

<?php while (have_posts()): the_post(); ?>
 <h4><?php the_title(); ?></h4>
 <p>
  <?php
    if ( has_post_thumbnail() ) {
      the_post_thumbnail();
    }
  ?>
 </p>
 <?php the_excerpt(); ?>
 <p><a target="_blank" href="<?php the_permalink(); ?>">Read more...</a></p>
<?php endwhile; ?>

An example snippet that will show the title, full post, but no image:

<?php while (have_posts()): the_post(); ?>
 <h4><?php the_title(); ?></h4>
 <?php the_content(); ?>
 <p><a target="_blank" href="<?php the_permalink(); ?>">Read more...</a></p>
<?php endwhile; ?>

If anybody would like to add some more code examples to the comments, I’ll be glad to see them and we’ll get them added to the main post to build up a little library of useful snippets.

 

 

 

Share this post:
read more

The best blackberry crumble recipe on the internet

blackberry-crumble

Now that is a ridiculously bold claim in the title, but I do believe after amalgamating several recipes for this classic English dessert, I’ve finally nailed one that I will use over and over.

Hope you enjoy it if you venture to make it.

Ingredients:

  • 200g plain flour
  • 100g butter
  • 50g caster sugar
  • 50g porridge oats
  • A punnet of blackberries (fresh or frozen)
  • Four apples (green are best)
  • Lots and lots more sugar for layering

Method:

  1. Preheat your oven to 180C (160C fan), or gas mark 4 (I think).
  2. Grab a dish.  Anything.  Pie dish, casserole dish, or anything around 1.5-2 inches
  3. Prep the crumble.  Weigh your flour into a mixing bowl and rub in the butter until breadcrumb like flakes emerge.  This doesn’t need to be perfect, as some lumpier bits will add to the textures at the end.
  4. Add the sugar and the oats.  Again, rub this together to achieve a breadcrumb consistency.
  5. Peel your apples.
  6. Using a knife slice around the edge of the apples, the get some thin slices,  stopping at the core.
  7. Rub some butter around the dish, to stop the fruit sticking to the sides and bottom.
  8. Add one thin layer of apple to the bottom of the dish.
  9. Sprinkle with some sugar.
  10. Add a layer of blackberries.
  11. Sprinkle with sugar
  12. Keep going with steps 8 to 11, until you have used all of your fruit.  Neatness is NOT the key here,  as this is a homely crumble, not a work of art.
  13. Spread your crumbly crumble mix onto the top of the fruit.
  14. Add another layer of sugar.
  15. Cook in the oven for 35-40 minutes if you’ve used fresh blackberries, or 45-50 minutes if you’ve used frozen.  Make sure the top doesn’t burn.
  16. Leave for 10-15 minutes before serving to ensure all the juices in the fruits thicken up.

A little note about the apples.  People do say that peeling and coring the apples is a necessity.  I disagree with anybody that gives this advice.  Unless you are producing a dessert where the apples will be on display, this is uncessary.  Just peel the apples using a standard veg peeler and then run the sides up and down the slicer edge of your standard kitchen grater.  Or, you can use a knife.  Or, if you’re posh and have one to hand, you can use a Mandolin.  Any of these will do the job just fine.

Share this post:
read more

Getting the value or text of an HTML attribute using jQuery

Grabbing attributes to use in your JavaScript is often handy.  HTML attributes can be used to send various options to your script or attributes used for multiple switches to control different elements of what you are doing.

You can use HTML attributes on their own, or grab them from specific elements with this.

If you are using a standalone element, such as:

<button class="btn btn-outline-success btn-sm buyButton" value="profile" customTitle="Profile Upgrade">BUY</button>

You can use a specific selector:

const itemTitle = $('.buyButton').attr('customTitle');

If you are using multiple selectors, then you can grab the values from the button you want, when using onClick, for example, in a similar way.

So if you have:

<div class="col-sm-2">
    <button class="btn btn-outline-success btn-sm buyButton" value="profile" customTitle="Profile Upgrade">BUY</button>
</div>
<div class="col-sm-2">
    <button class="btn btn-outline-success btn-sm buyButton" value="listing" customTitle="Listing Upgrade">BUY</button>
</div>
<div class="col-sm-2">
    <button class="btn btn-outline-success btn-sm buyButton" value="highlight" customTitle="Highlight Listing">BUY</button>
</div>

(I’ve made some of these up, and some of the bits are unnecessary, like the DIV’s, they are just in the project I’m working on)

So if you want to get the customTitle attribute to use in your logic somewhere, use:

$(".buyButton").on('click', function(e) {
    e.preventDefault();
    const customTitle = $(this).attr('customTitle');
})

 

Share this post:
read more

Get the value of selected radio buttons – jQuery

If you need to get the value of a selected radio button dynamically, to send for processing via an AJAX call for example, then the following is a great way to achieve this.

The general methodology is to give all of the radio options a generic class that can be used to trigger the onchange event. Then, grab the value of the radio button that has been selected and use it in your processing script.

In the below example, we use the “class” to define the group, the “name” to define what we are selecting, and the “value” to determine what is then sent to the processing script.

The radio buttons:

<div class="row">
  <div class="col-sm-6">
    Option 1
  </div>
  <div class="col-sm-6">
    <div class="form-check-inline">
      <label class="form-check-label">
        <input type="radio" class="form-check-input viewChange" name="option1" value="show" checked>Show
      </label>
    </div>
    <div class="form-check-inline">
      <label class="form-check-label">
        <input type="radio" class="form-check-input viewChange" name="option1" value="hide">Hide
      </label>
    </div>
  </div>
</div>
<div class="row">
  <div class="col-sm-6">
    Option 2
  </div>
  <div class="col-sm-6">
    <div class="form-check-inline">
      <label class="form-check-label">
        <input type="radio" class="form-check-input viewChange" name="option2" value="show" checked>Show
      </label>
    </div>
    <div class="form-check-inline">
      <label class="form-check-label">
        <input type="radio" class="form-check-input viewChange" name="option2" value="hide">Hide
      </label>
    </div>
  </div>
</div>
<div class="row">
  <div class="col-sm-6">
    Option 3
  </div>
  <div class="col-sm-6">
    <div class="form-check-inline">
      <label class="form-check-label">
        <input type="radio" class="form-check-input viewChange" name="option3" value="show" checked>Show
      </label>
    </div>
    <div class="form-check-inline">
      <label class="form-check-label">
        <input type="radio" class="form-check-input viewChange" name="option3" value="hide">Hide
      </label>
    </div>
  </div>
</div>

There’s a lot of Bootstrap 4 formatting in there as well, as this was taken from one of my live projects.  I have also used the values “show” and “hide”, as these are project specific, but you could add any values you require in here.

Then some JavaScript to do the actual work:

$(".viewChange").on("change", function(e){

    e.preventDefault();

    const option1status = $("input[name='option1']:checked").val();
    const option2status = $("input[name='option2']:checked").val();
    const option3status = $("input[name='option3']:checked").val();

    /*
    Do something with your now created constants
    */

});

 

This will produce the outputs you need to then do processing as you require.

Share this post:
read more

Ensure only a UK decimal value is added to a textbox – JavaScript

If you are adding a price, or a value to a textbox input, you may need to sanitise it.  This script will make sure that nothing is allowed in the box except for a decimal point and numeric values.  It will also ensure that there is only two numbers after the decimal place and that there can only be one decmial place.

$('#someTextInput').keypress(function(event) {
        var $this = $(this);
        if ((event.which !== 46 || $this.val().indexOf('.') !== -1) &&
            ((event.which < 48 || event.which > 57) &&
                (event.which !== 0 && event.which !== 8))) {
            event.preventDefault();
        }

        var text = $(this).val();
        if ((event.which === 46) && (text.indexOf('.') === -1)) {
            setTimeout(function() {
                if ($this.val().substring($this.val().indexOf('.')).length > 3) {
                    $this.val($this.val().substring(0, $this.val().indexOf('.') + 3));
                }
            }, 1);
        }

        if ((text.indexOf('.') !== -1) &&
            (text.substring(text.indexOf('.')).length > 2) &&
            (event.which !== 0 && event.which !== 8) &&
            ($(this)[0].selectionStart >= text.length - 2)) {
            event.preventDefault();
        }
    });

    $('#someTextInput').bind("paste", function(e) {
        var text = e.originalEvent.clipboardData.getData('Text');
        if ($.isNumeric(text)) {
            if ((text.substring(text.indexOf('.')).length > 3) && (text.indexOf('.') > -1)) {
                e.preventDefault();
                $(this).val(text.substring(0, text.indexOf('.') + 3));
            }
        }
        else {
            e.preventDefault();
        }
    });

 

Share this post:
read more

Queso Cheese Dip (Mexican Cheese Dip)

The ultimate “smother over nachos” dip.

This cheese dip is amazing.  It reminds me of the dip that comes smothered over nachos in cinemas and other places.  It has that delicious, moreish taste that you want to keep eating.

It does pay you to slowly cook the garlic and onions. I mean, slowly. I think I spent over 20 minutes over a shallow heat softening everything up.

One final note is that I like a spicy dip and with the amount of Jalopeno’s below, it is quite tangy.  You can increase or decrease this amount to taste.

Ingredients

  • 225 g Cheddar Cheese
  • 1 tbsp cornflour
  • 8 g butter
  • One large garlic clove, minced
  • 1/4 small white onion, very finely chopped
  • 375g evaporated milk
  • One small tomato, very finely diced
  • 1/4 tsp onion powder
  • 1/4 tsp garlic powder
  • 1/4 tsp cumin
  • 113g jar Jalapeno Peppers
  • 1/4 cup coriander/cilantro, finely chopped
  • 2 – 3 tbsp milk
  • Salt

Instructions

  1. Toss the cheese and cornflour in a bowl to coat.
  2. In a heavy bottom saucepan, melt the butter, then add the garlic/onion, cooking until both are soft, but neither are brown.
  3. Add tomato, juices and all, and cook for 2 minutes until tomato softens.
  4. Add evaporated milk and cheese. Stir, then add chiles and Spices.
  5. Add the cheese, stirring continuously.
  6. Add salt to taste – the amount required depends on the saltiness of cheese used
  7. Stir through the coriander.
  8. Add a splash of milk to thin down the sauce.  The sauce will thicken as it cools, so some trial and error may be required.
  9. Remove from heat. Serve warm or at room temperature – it will be soft and scoopable even when it cools.
Share this post:
read more

Explode a multi-dimensional array (PHP)

php-banner

Sometimes you need to explode more than just a single dimension array.  In the case of a project I worked on recently, I was given this data, taken from MySQL in the form of a string.

bromsgrove:27.83|crawley:153.34|manchester:119.5|peterborough:125.62|

So, this is four locations, with a respective distance.

The trick with splitting them up, using PHP explode(), is to do it in two parts.  In this case, I first want to split them into units of warehouse location and distance, which is achieved like this:

$firstArray= explode('|',$distanceData->distance);

This will then produce an array that looks like this:

array (size=5)
  0 => string 'bromsgrove:27.83' (length=16)
  1 => string 'crawley:153.34' (length=14)
  2 => string 'manchester:119.5' (length=16)
  3 => string 'peterborough:125.62' (length=19)
  4 => string '' (length=0)

The problem with this, of course, is that the delimiter is added to the end of every location that is concatenated onto the end of the string when the data is being produced, so the next step is to get rid of the last character, which [in this case and many others], will always be tagged onto the end of a string like this.  We can do this with PHP substr().

$distanceData = substr($distanceData,0,-1);

So now when the array is produced, it doesn’t have the empty slot at the end.

array (size=4)
  0 => string 'bromsgrove:27.83' (length=16)
  1 => string 'crawley:153.34' (length=14)
  2 => string 'manchester:119.5' (length=16)
  3 => string 'peterborough:125.62' (length=19)

We now have 4 arrays that all need exploding, so it’s simply a case of cycling through each with a foreach loop and creating a new exploded array each time:

foreach($firstArray as $key => $data)
{
   $distance[$key]= explode(':',$data);
}

Which will give the final result we are looking for, a fully split-up, two-dimensional array, created from a delimited string.

array (size=4)
  0 => 
    array (size=2)
      0 => string 'bromsgrove' (length=10)
      1 => string '27.83' (length=5)
  1 => 
    array (size=2)
      0 => string 'crawley' (length=7)
      1 => string '153.34' (length=6)
  2 => 
    array (size=2)
      0 => string 'manchester' (length=10)
      1 => string '119.5' (length=5)
  3 => 
    array (size=2)
      0 => string 'peterborough' (length=12)
      1 => string '125.62' (length=6)

Although this array is OK, it does still need some work to make it super easy to use.  This can be done by whittling it down further, whilst already inside the foreach loop.

First, initialise an array:

$hubDistance= array();

Then build this array as you loop through using the data provided from the explode.

foreach ($firstArray as $key => $data) {
    $distance[$key] = explode(':', $data);
    $hubDistance[$distance[$key][0]] = (float)$distance[$key][1];
}

This will strip out any of the unnecessary levels in the array and leave you with something like this:

array (size=4)
  'bromsgrove' => float 27.83
  'crawley' => float 153.34
  'manchester' => float 119.5
  'peterborough' => float 125.62

Which is much better!

I’ve explicitly called float on the numbers for this project, but PHP will typically sort this out for you.

Update:

I keep needing to use this on various projects, so I’ve whittled it down to a function if anybody needs to use it:

function stringToArray($string)
{

    /*
     * This relies on the string being in the format
     * a1:a1a¬b1:b1a¬c1:c1a¬ [etc]
     * Individual separator = :
     * Group / cluster separator = ¬
     */

    $string = mb_substr($string,0 ,-1);

    $firstArray = explode("¬",$string);

    $cleanArray = array();

    foreach ($firstArray as $key => $data) {
        $innerArray[$key] = explode(':', $data);
        $cleanArray[$innerArray[$key][0]] = $innerArray[$key][1];
    }

    return $cleanArray;

} 

So if you input a string like this :

$inputString = "sw4:33¬sw5:44¬swnh4:23¬swnh5:0¬mw4:223¬mw5:233¬mwnh4:433¬mwnh5:45¬"

Then use the function:

var_dump(stringToArray($inputString);

You’ll end up with something that looks like this:

array (size=8)
  'sw4' => string '33' (length=2)
  'sw5' => string '44' (length=2)
  'swnh4' => string '23' (length=2)
  'swnh5' => string '0' (length=1)
  'mw4' => string '223' (length=3)
  'mw5' => string '233' (length=3)
  'mwnh4' => string '433' (length=3)
  'mwnh5' => string '45' (length=2)

Probably no use to anybody, but it’s there if you need it 🙂
 

Share this post:
read more

PHP function to match worldwide VAT numbers

php-banner

From another site, but jotted down here for reference in the future:

function checkVatNumber( $country, $vat_number ) {
    switch($country) {
        case 'Austria':
            $regex = '/^(AT){0,1}U[0-9]{8}$/i';
            break;
        case 'Belgium':
            $regex = '/^(BE){0,1}[0]{0,1}[0-9]{9}$/i';
            break;
        case 'Bulgaria':
            $regex = '/^(BG){0,1}[0-9]{9,10}$/i';
            break;
        case 'Cyprus':
            $regex = '/^(CY){0,1}[0-9]{8}[A-Z]$/i';
            break;
        case 'Czech Republic':
            $regex = '/^(CZ){0,1}[0-9]{8,10}$/i';
            break;
        case 'Denmark':
            $regex = '/^(DK){0,1}([0-9]{2}[ ]{0,1}){3}[0-9]{2}$/i';
            break;
        case 'Estonia':
        case 'Germany':
        case 'Greece':
        case 'Portugal':
            $regex = '/^(EE|EL|DE|PT){0,1}[0-9]{9}$/i';
            break;
        case 'France':
            $regex = '/^(FR){0,1}[0-9A-Z]{2}[ ]{0,1}[0-9]{9}$/i';
            break;
        case 'Finland':
        case 'Hungary':
        case 'Luxembourg':
        case 'Malta':
        case 'Slovenia':
            $regex = '/^(FI|HU|LU|MT|SI){0,1}[0-9]{8}$/i';
            break;
        case 'Ireland':
            $regex = '/^(IE){0,1}[0-9][0-9A-Z+*][0-9]{5}[A-Z]$/i';
            break;
        case 'Italy':
        case 'Latvia':
            $regex = '/^(IT|LV){0,1}[0-9]{11}$/i';
            break;
        case 'Lithuania':
            $regex = '/^(LT){0,1}([0-9]{9}|[0-9]{12})$/i';
            break;
        case 'Netherlands':
            $regex = '/^(NL){0,1}[0-9]{9}B[0-9]{2}$/i';
            break;
        case 'Poland':
        case 'Slovakia':
            $regex = '/^(PL|SK){0,1}[0-9]{10}$/i';
            break;
        case 'Romania':
            $regex = '/^(RO){0,1}[0-9]{2,10}$/i';
            break;
        case 'Sweden':
            $regex = '/^(SE){0,1}[0-9]{12}$/i';
            break;
        case 'Spain':
            $regex = '/^(ES){0,1}([0-9A-Z][0-9]{7}[A-Z])|([A-Z][0-9]{7}[0-9A-Z])$/i';
            break;
        case 'United Kingdom':
            $regex = '/^(GB){0,1}([1-9][0-9]{2}[ ]{0,1}[0-9]{4}[ ]{0,1}[0-9]{2})|([1-9][0-9]{2}[ ]{0,1}[0-9]{4}[ ]{0,1}[0-9]{2}[ ]{0,1}[0-9]{3})|((GD|HA)[0-9]{3})$/i';
            break;
        default:
            return -1;
            break;
    }
   
    return preg_match($regex, $vat_number);
}

 

Share this post:
read more

1 2 3 4 6