Current location: Hot Scripts Forums » General Community » Script Requests » Phone No. (000) 000-000 Script


Phone No. (000) 000-000 Script

Reply
  #1 (permalink)  
Old 09-12-07, 01:26 PM
samot samot is offline
Newbie Coder
 
Join Date: Apr 2007
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Phone No. (000) 000-000 Script

Hi,
I am looking for a script to use for my contact form html.
I have a Phone field with hint: (000) 000-0000 format.

I want to remove the hint. But I want "(" ")" brackets be automatic included in the field as the user enter the phone number.

If user enter phone number: 1234567890
It will automatically do this: (123) 456-7890

Is this possible ?
Thanks,

Samot

Last edited by samot; 09-12-07 at 01:40 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-12-07, 01:42 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
javascript Code:
  1. <script type="text/javascript">
  2. function format_phone(obj)
  3. {
  4.     if (window.RegExp)
  5.     {
  6.         if (obj.value.match(/^\d{3}$/))
  7.         {
  8.             obj.value = obj.value.replace(/^(\d{3})/, '($1) ');
  9.         }
  10.         else if (obj.value.match(/^\(\d{3}\)\s?(\d{3,})$/))
  11.         {
  12.             obj.value = obj.value.replace(/(\d{3})\s?(\d+)$/, '$1-$2');
  13.         }
  14.     }
  15. }
  16. </script>
  17.  
  18. <input type="text" onkeydown="format_phone(this);" />
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-12-07, 01:44 PM
Boraan's Avatar
Boraan Boraan is offline
Coding Addict
 
Join Date: Jul 2007
Location: Clayton, NC
Posts: 292
Thanks: 0
Thanked 1 Time in 1 Post
instead of using 1 text field in your form, use three fields. phone1 phone2 phone3.

Then you join the form data into one string. $phone = "(phone1) phone2-phone3"

I purposely left out any defining markup in the string because I don't know what language you're designing in, but it would be the form values.

That way is a whole lot easier than splitting the variable then putting it back together again. This way it's already split for you.

Edit: Nico's works too, but keep in mind that not all browsers have Javascript enabled, and there are a few out there that use a different java engine and it may be incompatible.
__________________
Dexter Nelson
Techdex Development & Solutions
========================
Internet Marketing For Programmers | Free Market Research in 15 Minutes or Less
My Software: Hotscripts Softpedia software.techdex.net
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 09-12-07, 02:01 PM
samot samot is offline
Newbie Coder
 
Join Date: Apr 2007
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Nico and Boraan! This is great.

My manager is lazy...so he wants to type in any number and it auto it for him..ekeke

Originally, I thought of using what Boraan mentioned. But it's not what he was looking for.

See, I am using the DWCS3 Spry to validate all the fields in my form.

So, what is that snippet called?
Where can I find out more info about these things here: /^\(\d{3}\)\s?(\d{3,})$/

Thanks again.

Samot
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 09-12-07, 02:13 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
This snippet doesn't have a name. But it's using regular expressions.


www.regular-expressions.info
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 09-12-07, 04:25 PM
Boraan's Avatar
Boraan Boraan is offline
Coding Addict
 
Join Date: Jul 2007
Location: Clayton, NC
Posts: 292
Thanks: 0
Thanked 1 Time in 1 Post
heh. the way I mentioned is way easy. it's only a slight change to the form and simply putting the string together how you want it. I give it a few lines of code to define it in the script. in Perl I can define it in one line, in ASP? The same... one line. Then give it 3 or 4 lines to validate. It really is very easy.
__________________
Dexter Nelson
Techdex Development & Solutions
========================
Internet Marketing For Programmers | Free Market Research in 15 Minutes or Less
My Software: Hotscripts Softpedia software.techdex.net
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Php WYWO (While You Were Out) Phone Message script trippo Script Requests 0 05-29-07 09:59 PM
Autohits script taurri Traffic Exchange 1 02-24-06 12:28 PM
Is there any integrity of script rankings? webmaster@atmanager.com Hot Scripts Forum Questions, Suggestions and Feedback 17 08-06-04 01:12 AM
Affiliate script (PHP) whtiebear Job Offers & Assistance 2 12-21-03 01:12 AM


All times are GMT -5. The time now is 12:39 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.