Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best solution (in my opinion) would be to use multiple regular expressions, each one for a different format. Regular expressions tend to grow quite large quite fast so maintaining them can be a daunting experience.</p> <p>What I would do would be to use something like these:</p> <ul> <li><code>(2)[ -]+(\d{2})[ -]+(\d{2})[ -]+(\d{2})</code> to match the first pattern (new land line phones): <code>2-XX-XX-XX</code>.</li> <li><code>(\d{2})[ -]+(\d{2})[ -]+(\d{2})</code> to match the second pattern (old land line phones): 6 digits.</li> <li><code>(8\d{2})[ -]+(\d{2})[ -]+(\d{2})[ -]+(\d{2})</code> to match the third pattern (old mobile phones): <code>8XX-YY-YY-YY</code>.</li> <li><code>(5\d{2})[ -]+(\d{2})[ -]+(\d{2})[ -]+(\d{2})</code> to match the fourth pattern (new mobile phones): <code>5XX-YY-YY-YY</code>.</li> </ul> <p>You will have to use the above expressions to see which expression will match the format of the number you have entered. Note that these expressions assume that the numbers making up the phone number are separated by a white space (<code></code>) or a dash (<code>-</code>).</p> <p>If the pattern will match, the regular expression engine will also throw in the numbers making up the phone number into groups, denoted by the <code>(</code> and <code>)</code> brackets. You can then reconstruct the phone number in any way you wish by accessing these groups and create new strings representing the newly formatted phone.</p> <p>To see how you can use regular expression groups in Javascipt, please take a look <a href="https://stackoverflow.com/questions/432493/how-do-you-access-the-matched-groups-in-a-javascript-regex">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload