Formatting phone numbers

This topic contains 3 replies, has 2 voices, and was last updated by  Kor 7 years, 2 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket

Tagged: 

  • Author
    Posts
  • #345503

    Michael Browning
    Buyer
    Post count: 17

    We’d like to enforce some consistent formatting of phone numbers across our site. Ideally we’d do this during the process for adding a listing as currently clients are able to add non-numeric characters such as letters to the phone number field. What’s the best/simplest way to make this change?

    #345525

    Kor
    Moderator
    Post count: 16516

    Hi Michael,

    I’ve just checked with a developer and to achieve this, insert the JS script below into GD > Design > Scripts > Header script code . This code only applies to “Custom Fields”

    
    
    jQuery('input[field_type="phone"],input[type="tel"]').on("contextmenu", function(e) {
        return false;
    });
    jQuery(document).on('keypress', 'input[field_type="phone"],input[type="tel"]', function(e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (jQuery.inArray(e.key, ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", " ", "+"]) !== -1) {
            return true;
        } else if (e.ctrlKey || e.shiftKey) {
            return false;
        } else if (jQuery.inArray(key, [8, 35, 36, 37, 39, 46]) !== -1) {
            return true;
        }
        return false;
    });

    Thanks!

    #347970

    Michael Browning
    Buyer
    Post count: 17

    So to make this work we’ll need to create a custom field to replace the current telephone field and then add this bit to the scripts?

    #347978

    Kor
    Moderator
    Post count: 16516

    Hi Michael,

    This code snippet will work on all “Phone” custom fields https://wpgeodirectory.com/docs/core-place-settings/#phone . If you already have a phone field, just insert the code into GD > Design > Scripts > Header script code .

Viewing 4 posts - 1 through 4 (of 4 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket