Title: UK Phone validation
Last modified: June 15, 2017

---

# UK Phone validation

 *  Resolved [the_shopkeeper](https://wordpress.org/support/users/the_shopkeeper/)
 * (@the_shopkeeper)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/uk-phone-validation/)
 * When adding a new event I’m trying to add a phone number, but whatever I do –
   it’s always invalid.
    I’ve set locale to global – pasted in the regex – but still
   it’s invalid.
 * I’d rather not validate the phone number – is there a way to switch off phone
   validation?
    I’ve tried leaving the Phone Regex field empty. Invalid.
 * Are there other UK users using this Plugin who can share ideas and tips?
 * So close to being a brilliant plugin. 🙂

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [Cleveland Heights-University Heights Public Library Webdeveloper](https://wordpress.org/support/users/chuhpl/)
 * (@chuhpl)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/uk-phone-validation/#post-9234566)
 * Can you try another regex?
 * ^((\(?0\d{4}\)?\s?\d{3}\s?\d{3})|(\(?0\d{3}\)?\s?\d{3}\s?\d{4})|(\(?0\d{2}\)?\
   s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$
 *  Plugin Author [Cleveland Heights-University Heights Public Library Webdeveloper](https://wordpress.org/support/users/chuhpl/)
 * (@chuhpl)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/uk-phone-validation/#post-9234570)
 * I’m not the greatest RegEx writer, so I’m hunting around for good ones that will
   work for UK.
 *  Thread Starter [the_shopkeeper](https://wordpress.org/support/users/the_shopkeeper/)
 * (@the_shopkeeper)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/uk-phone-validation/#post-9235360)
 * I just don’t think the Phone RegEx field works! 🙁
 * Example – Locale Admin – Address type – Global.
 * Entering the Contact Phone number of (612) 239-0036 will always be valid, no 
   matter what RegEx example is pasted into the Phone RegEx field.
 * Also – if /^[A-z]+$/ was added to the Phone RegEx field – any ‘word’ would be
   valid.
    -  This reply was modified 9 years, 2 months ago by [the_shopkeeper](https://wordpress.org/support/users/the_shopkeeper/).
 *  Plugin Author [Cleveland Heights-University Heights Public Library Webdeveloper](https://wordpress.org/support/users/chuhpl/)
 * (@chuhpl)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/uk-phone-validation/#post-9235401)
 * On my test site, I used this:
 * `/^((\(?0\d{4}\)?\s?\d{3}\s?\d{3})|(\(?0\d{3}\)?\s?\d{3}\s?\d{4})|(\(?0\d{2}\)?\
   s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$/`
 * THis validated against a made up number ((028) 3722 4444). Can you try this one?
 * I also tried /^[A-z]+$/ and it works for words like “bob” but not numbers.
 * You can also try /.*$/ to allow anything through.
 *  Thread Starter [the_shopkeeper](https://wordpress.org/support/users/the_shopkeeper/)
 * (@the_shopkeeper)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/uk-phone-validation/#post-9239057)
 * Thanks for your efforts on this – it really is appreciated.
 * I echo my earlier findings – my installation simply doesn’t demonstrate that 
   the Phone RegEx field works.
 * I’ve put in all the test data – same result – “You must enter a valid contact
   phone number”
 * ‘Bob’ didn’t even work.
 * Wordpress 4.8 if that matters.
 * Kr.
 *  Plugin Author [Cleveland Heights-University Heights Public Library Webdeveloper](https://wordpress.org/support/users/chuhpl/)
 * (@chuhpl)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/uk-phone-validation/#post-9241231)
 * I was looking at the public phone validation for registering and such. This is
   in the Admin area making events, correct?
 * I just realized that the Admin event checking does NOT use the regex at all, 
   as you said.
 * It may take me a bit of time to put out a version for that, but I can let you
   know what to comment out if you want so that it works for now!
 * In the file bookaroom-events.php, lines 1472 and 1481 are the phone validation.
 *     ```
       		if( !empty( $externals['publicPhone'] ) ) {
       			$cleanPhone = preg_replace( "/[^0-9]/", '', $externals['publicPhone'] );
       			if ( strlen( $cleanPhone ) == 11 ) {
       				$cleanPhone = preg_replace( "/^1/", '', $cleanPhone );
       			}			
       			if( !is_numeric( $cleanPhone ) || strlen( $cleanPhone ) !== 10 ) {
       				$final[] = __( 'You must enter a valid contact phone number.', 'book-a-room' ); 
       				$errorBG['publicPhone'] = true;
       			}
       		}
       ```
   
 * If you add a # to the beginnings of lines 1478 and 1479, it shouldn’t throw an
   error. Your final should be:
 *     ```
       		if( !empty( $externals['publicPhone'] ) ) {
       			$cleanPhone = preg_replace( "/[^0-9]/", '', $externals['publicPhone'] );
       			if ( strlen( $cleanPhone ) == 11 ) {
       				$cleanPhone = preg_replace( "/^1/", '', $cleanPhone );
       			}			
       			if( !is_numeric( $cleanPhone ) || strlen( $cleanPhone ) !== 10 ) {
       				#$final[] = __( 'You must enter a valid contact phone number.', 'book-a-room' ); 
       				#$errorBG['publicPhone'] = true;
       			}
       		}
       ```
   
 * Once I’ve redone the templates and converted everything over for translation (
   getting close), I’ll correct this validation to use the regex.
 *  Thread Starter [the_shopkeeper](https://wordpress.org/support/users/the_shopkeeper/)
 * (@the_shopkeeper)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/uk-phone-validation/#post-9247920)
 * Great – that explains it, and commenting out these lines has finally allowed 
   me to post an event. Thank you for that.
    -  This reply was modified 9 years, 1 month ago by [the_shopkeeper](https://wordpress.org/support/users/the_shopkeeper/).
 *  Plugin Author [Cleveland Heights-University Heights Public Library Webdeveloper](https://wordpress.org/support/users/chuhpl/)
 * (@chuhpl)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/uk-phone-validation/#post-9248226)
 * I am glad that did it for you. Once I get this big update done and tested, I’ll
   make a real fix for this.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘UK Phone validation’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/book-a-room_f4ece6.svg)
 * [Book a Room](https://wordpress.org/plugins/book-a-room/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/book-a-room/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/book-a-room/)
 * [Active Topics](https://wordpress.org/support/plugin/book-a-room/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/book-a-room/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/book-a-room/reviews/)

## Tags

 * [locale](https://wordpress.org/support/topic-tag/locale/)

 * 8 replies
 * 2 participants
 * Last reply from: [Cleveland Heights-University Heights Public Library Webdeveloper](https://wordpress.org/support/users/chuhpl/)
 * Last activity: [9 years, 1 month ago](https://wordpress.org/support/topic/uk-phone-validation/#post-9248226)
 * Status: resolved