Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 18th, 2006, 05:01 AM
Authorized User
 
Join Date: Oct 2006
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default Phone # field formatting!

Hello,

I have an existing asp.net page that asks for a customer's US phone number. Unfortunately, the field is set up to only accept entries in an unbroken number string, i.e.

6178899923

instead of

617-889-9923 or (617) 889-9923

How might I set up the field to accept phone numbers in one of these formats? I don't care as much how the number is stored in SQL, rather I want to make it easier for the customer. The unbroken string format is not familiar to a typical US user, and the form currently returns an error if dashes or brackets are used. For reference:

<code><tr>
                  <td width="110" class="content"> Phone
                  </td>
                  <td><input name="sphone" type="text" id="sphone" size="20" maxlength="15" style="BACKGROUND-COLOR: lavender" value="<%=sphone%>" /></td>
                </tr></code>

Thank you very much.
 
Old December 18th, 2006, 05:57 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

There are a few ways to do this. You can use a RegularExpress or Custom validator. you could create 3 textboxes (area code) (Prefix) (number) and use javascript to set focus to the next textbox after they have entered it. The easiest way, what I would do, is just let them enter what ever they want. On submit of the form, loop through each character in the textbox and strip out anything that is not numeric.

Jim

 
Old December 19th, 2006, 12:49 PM
Authorized User
 
Join Date: Oct 2006
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by jbenson001
 There are a few ways to do this. You can use a RegularExpress or Custom validator. you could create 3 textboxes (area code) (Prefix) (number) and use javascript to set focus to the next textbox after they have entered it. The easiest way, what I would do, is just let them enter what ever they want. On submit of the form, loop through each character in the textbox and strip out anything that is not numeric.

Jim
Thank you for the ideas!
 
Old December 19th, 2006, 02:02 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

no problem.. good luck







Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView - Phone column formatting jnks2005 ASP.NET 2.0 Basics 1 February 14th, 2007 06:36 PM
formatting phone numbers xslt_student XSLT 0 August 7th, 2006 04:10 PM
formatting integer field gloribel Crystal Reports 1 October 13th, 2005 12:27 PM
Formatting Querystring Field Name realgone_ VBScript 4 September 23rd, 2004 07:52 AM
Formatting a Field Containing a Time to AM/PM taleriana XSLT 2 March 16th, 2004 11:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.