Jump to content

Recommended Posts

Posted

I use the "Choose Phone Format' rule a lot and appreciate it's ease.

However, I now am being asked for multiple options for European style phone numbers.

The first one I need is to have a result that looks like this:  555 666-6666

There is only a space after the 'area' code and a dash between the exchange and the number itself.

I tried editing the code by converting the code to javascript but was not successful.

Shortly I will be asked for phone formats based on country codes, which vary a lot.  

The country code can be wither a 2 or a 3-character code

The actual phone numbers vary too ... it could be this:  +49 000 000-0000 (3 digit after country code)

or it could be this:  +345 0000 000-0000 (4-digit after country code)

Is there a solution you can offer?

Thanks so much

 

Posted

So, two separate questions here.  For the European numbers, I would create the Choose Phone Format rule so that it returns the number with dashes (format 123-456-7890), then create another rule, a JavaScript rule this time, and have it replace the first dash with a space, like so:

return Rule("Choose Phone Format: Phone").replace('-', ' ');

And use the JavaScript rule in the output.  Note that the main Form rule does NOT have to be converted to JavaScript.  The other rule can do the work to tweak the result.

The country codes are another story.  The current logic behind the Choose Phone Format rule doesn't support multi-digit country codes, nor those variations in the following digits.  It's not really designed for international numbers like that.  I would assume that such numbers are presented in the correct format in the first place in the data, and that trying to reformat them would possibly be destructive, but you seem to know more about these formats than I do.  You could trying Googling for something like "JavaScript format phone number with country code" to see what others have come up with.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...