I have a php validation of the UK phone number, inputed by potential clients in my form. It looks like this:
function phoneUK(phone){
var regex = /^(?:(?:(?:00\s?|\+)44\s?)|(?:\(?0))(?:\d{2}\)?\s?\d{4}\s?\d{4}|\d{3}\)?\s?\d{3}\s?\d{3,4}|\d{4}\)?\s?(?:\d{5}|\d{3}\s?\d{3})|\d{5}\)?\s?\d{4,5})$/i;
return regex.test(phone);
}
The problem is that in this form it only allows phone numbers with a 0 in front followed by ten digits (0XXXX XXXXXX
) and since recently there are also legitimate phone numbers with eleven digits after the leading zero.
How to alter the code so these type of phone numbers are allowed?
Try this:
Hope this helps.