[SOLVED] ensure proper formatting for phone #?

13 years 10 months ago #136603 by ThePiston
I'd like to have all my phone numbers in the DB as:

(XXX) XXX-XXXX

Is there any way to ensure this using the PERL feature?

Post edited by: krileon, at: 2010/07/06 15:52

CB 2.3, CBsubs 4.3, PHP 7.1, J! 3.9.X

Please Log in to join the conversation.

13 years 10 months ago #136608 by ThePiston
after doing some research I thought this would work, but it doesn't:

[code:1]/\(\d{3}\)\s\d{3}\-\d{4}/[/code:1]

Anyone done this already?

Post edited by: ThePiston, at: 2010/06/26 22:33

CB 2.3, CBsubs 4.3, PHP 7.1, J! 3.9.X

Please Log in to join the conversation.

13 years 10 months ago #136610 by heyai

hey-ai - the community for asian guys and non-asian girls

The search bar is your friend, not just decoration!

Please Log in to join the conversation.

13 years 10 months ago #136639 by ThePiston
I extrapolted his stuff for my uses with only one issue. When I use this code, the ?[ ]? allows anything it seems when I only want to allow a space.
[code:1]/([0-9]{3})?[ ]?[0-9]{3}-[0-9]{4}/[/code:1]

CB 2.3, CBsubs 4.3, PHP 7.1, J! 3.9.X

Please Log in to join the conversation.

13 years 10 months ago #136749 by krileon

I extrapolted his stuff for my uses with only one issue. When I use this code, the ?[ ]? allows anything it seems when I only want to allow a space.

Have tested your regex and it is working properly. Indeed the bracketed character only allows a single space, nothing else will validate. The question mark after it makes the space optional however, if you do not want that then try the following.

[code:1]
/^([0-9]{3}[ ])?[0-9]{3}-[0-9]{4}/
[/code:1]

The above would validate the following.

000 000-0000
000-0000

However would NOT validate the following.

000000-0000
0000000000
etc...

If you want ONLY 000 000-0000 you could use the following.

[code:1]
/[0-9]{3}[ ][0-9]{3}-[0-9]{4}/
[/code:1]


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 to join the conversation.

13 years 10 months ago #136754 by ThePiston
I actually want the parentheses around first 3 numbers, but this doesn't work:

[code:1]/([0-9]{3})[ ][0-9]{3}-[0-9]{4}/[/code:1]

CB 2.3, CBsubs 4.3, PHP 7.1, J! 3.9.X

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.330 seconds

Facebook Twitter LinkedIn