• Resolved the_shopkeeper

    (@the_shopkeeper)


    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)
  • 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}))?$

    I’m not the greatest RegEx writer, so I’m hunting around for good ones that will work for UK.

    Thread Starter the_shopkeeper

    (@the_shopkeeper)

    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.

    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

    (@the_shopkeeper)

    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.

    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

    (@the_shopkeeper)

    Great – that explains it, and commenting out these lines has finally allowed me to post an event. Thank you for that.

    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.