Format Phone Numbers

Format Phone Numbers

Pliachas PaschalisPliachas Paschalis Posts: 62Questions: 12Answers: 1

Any example of how to format phone numbers?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Is this in Editor (per the forum category you've posted this in) or in the DataTable?

    Allan

  • Pliachas PaschalisPliachas Paschalis Posts: 62Questions: 12Answers: 1

    It could be both!
    I made up this:

     { data: "Phone", render: function ( toFormat ) {
        return toFormat.toString().replace(
          /(\d\d\d)(\d\d\d)(\d\d\d\d)/g, '$1-$2-$3'
        ); }}
    

    should it be better to put a validator in such fields (FAX-mobile - Phone numbers) to count the numbers the user enters? For example 10 maximum?

  • Pliachas PaschalisPliachas Paschalis Posts: 62Questions: 12Answers: 1

    and this:

    { data: "FAX" ,render: function ( toFormat ) {
                    var tPhone;
                    tPhone=toFormat.toString();             
                    tPhone='(' + tPhone.substring(0,3) + ')' + tPhone.substring(3,6) + '-' + tPhone.substring(6,10);    
                    return tPhone }
                }
    
  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    I would certainly put a validator on it (all data should really have a validator).

    Your format assumes a US style telephone number. If that is valid for what you need then what you have is fine. You might also want to take a look at the Mask plug-in for Editor.

    Allan

  • Pliachas PaschalisPliachas Paschalis Posts: 62Questions: 12Answers: 1

    Thank you

  • Dirk FincleyDirk Fincley Posts: 38Questions: 3Answers: 0
This discussion has been closed.