Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

[SOLVED] Adding a phone number field (XXX) XXX-XXXX

  • danbo1972
  • danbo1972
  • OFFLINE
  • Posts: 88
  • Thanks: 22
  • Karma: 4
11 years 2 days ago - 10 years 11 months ago #236139 by danbo1972
Hello all. This is most likely the effects of another long day, but I can't, for the life of me, figure out how to add a field that displays a phone number on the user's profile, with the following format: (XXX) XXX-XXXX

I know this has been answered before with:
Regex:
[code:1]
\(?\b[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}\b
[/code:1]

Matches:
5555555555
555.555.5555
555-555-5555
555 555-5555
(555) 555-5555
But what I'm looking for is a set value or (###) ###-#### without allowing other options like ###.###.#### or ### ###-####. I'm shooting for a consistent look that isn't determined by the users input decisions.

Any suggestions would be appreciated.

Thanks!
Last edit: 10 years 11 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48473
  • Thanks: 8281
  • Karma: 1443
11 years 16 hours ago #236217 by krileon
Replied by krileon on topic Adding a phone number field (XXX) XXX-XXXX
Only way to apply formatting to a field is to use CB Query Field then query the database for the field and format it using SQL functions. Alternative is to develop a new CB plugin that uses CB triggers to parse through fields display functions and alters the output.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • danbo1972
  • danbo1972
  • OFFLINE
  • Posts: 88
  • Thanks: 22
  • Karma: 4
10 years 11 months ago #236542 by danbo1972
Replied by danbo1972 on topic Adding a phone number field (XXX) XXX-XXXX
Thanks for your response Kyle. You're trying to tell me something..... I just know it. :)

does anyone have sample code to put in the query. Someone out there has had to have done this before. I'm the furthest thing there is from a coder, but guidance gets me a long ways.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48473
  • Thanks: 8281
  • Karma: 1443
10 years 11 months ago - 10 years 11 months ago #236628 by krileon
Replied by krileon on topic Adding a phone number field (XXX) XXX-XXXX
The below should work.

Code:
SELECT CONCAT( LEFT( `cb_phonenumber`, 3 ) , '-', MID( `cb_phonenumber`, 4, 3 ) , '-', RIGHT( `cb_phonenumber`, 4 ) ) FROM `#__comprofiler` WHERE `id` = '[user_id]'

It'll format to 000-000-0000. Adjust as needed. Note I have not tested it so I've no idea if it'll actually work, but is just a guess based off SQL function usages.

Please see the below links for understanding of the functions used.

CONCAT: dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_concat
LEFT: dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_left
MID: dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_mid
RIGHT: dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_right


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Last edit: 10 years 11 months ago by krileon.
The following user(s) said Thank You: nant

Please Log in or Create an account to join the conversation.

  • danbo1972
  • danbo1972
  • OFFLINE
  • Posts: 88
  • Thanks: 22
  • Karma: 4
10 years 11 months ago #236745 by danbo1972
Replied by danbo1972 on topic Adding a phone number field (XXX) XXX-XXXX
That worked like a champ. You'll be happy to know I am enrolling in a few classes this semester to help me better understand SQL and databases in general. In the meantime, I appreciate your guidance.
The following user(s) said Thank You: krileon

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum