Author |
Topic |
cjhardie
Yak Posting Veteran
58 Posts |
Posted - 2006-09-21 : 09:43:32
|
Is there any way to make a textbox into the format of ###-#### so the hyphen is always there or a way for an error message to prompt if someone did not insert the hyphen?? |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-09-21 : 09:47:14
|
I think there is a FORMAT something property you can set...Peter LarssonHelsingborg, Sweden |
 |
|
dfiala
Posting Yak Master
116 Posts |
Posted - 2006-09-21 : 10:02:52
|
There is no native masked control to do this. You either need to:1) use a third party control, either license one or use something like this: http://www.codeproject.com/useritems/Xtended_TextBox.asp2) add a regex validator to your form to check for the proper format3) add the hyphen yourself before you save the dataI'd favor option 3. If the user enters 7 digits, you know where to stick the hyphen, why force the user to go through the effortDean FialaVery Practical Software, IncNow with Blogging...http://www.vpsw.com/blogbabyMicrosoft MVP |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-09-21 : 10:04:10
|
i'd go with #2. regex is a best bet.3 isn't as good because users are set in their ways and they don't want to change.Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
dfiala
Posting Yak Master
116 Posts |
Posted - 2006-09-21 : 10:10:38
|
That's exactly why you go with 3, don't make the users change or think. Let 'em enter the info any old way that the software can figure out.http://www.amazon.com/About-Face-2-0-Essentials-Interaction/dp/0764526413/sr=8-1/qid=1158847818/ref=pd_bbs_1/103-2982630-1495037?ie=UTF8&s=booksDean FialaVery Practical Software, IncNow with Blogging...http://www.vpsw.com/blogbabyMicrosoft MVP |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-09-21 : 10:18:18
|
well i understood you that in #3 you meant to allow them to enter only numbers.but if you add a hyphen yourself, then what happens if a user already enters the hyphen?Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
dfiala
Posting Yak Master
116 Posts |
Posted - 2006-09-21 : 10:24:08
|
Then they've already added the hyphen. Simple enough to check for. Only add it if necessary.Dean FialaVery Practical Software, IncNow with Blogging...http://www.vpsw.com/blogbabyMicrosoft MVP |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-09-21 : 11:08:46
|
and we're back to option 2 if a user enters a ( or ) or - you'd have to hande each with an if.using regex solves this.NEVER trust a user's entry.Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
dfiala
Posting Yak Master
116 Posts |
Posted - 2006-09-21 : 11:17:36
|
Exactly! But why force the user to enter a hyphen?Sigh. Why are you making the user work instead of making the code work?You don't even need to use an if statementStrip what you get at the back end to the bare numbers (easily done with regex) and either enter a hyphen or don't -- but don't make the user have to worry about formatting that is meaningless to the data.Dean FialaVery Practical Software, IncNow with Blogging...http://www.vpsw.com/blogbabyMicrosoft MVP |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-09-21 : 11:29:15
|
i'm saying that some users have it in their blood to type a phone numberas (123) 112-34232-321 or some other formatI agree with you because my original understanding was that you meant only numbers be allowed into the textboxGo with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
dfiala
Posting Yak Master
116 Posts |
Posted - 2006-09-21 : 11:42:59
|
All you care about is:12311234232321 This is the phone numebr.Everything else is formatting.So they type it in with hyphensor parensor dotsor spacesOr they don'tWhy force them to enter it in your formatting?Get only the numbers from the string that was entered.If it has a viable number of digits, use it, format it, save it. If you can't make it into a phone number, ie, it only has 6 digits, then warn them or even refuse to save it if you must, but why make the user enter the same data twice because they forgot a hyphen -- or added a space? Make your code smarter so the user doesn't have to work harder.Dean FialaVery Practical Software, IncNow with Blogging...http://www.vpsw.com/blogbabyMicrosoft MVP |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-09-21 : 12:09:47
|
The easiest solution is to break it out for them and force them to enter the multiple parts into multiple textboxes, each restricted to only allow the correct content.i.e., display the form like this to them:Your Phone Number: ( [xxx] ) [xxx] - [xxxx] where each [xx] is a separate text box that only accepts that portion of the number .. . Make each one only allow digits, and only the correct count (3 or 4) . Make it clear what data is expected in which textbox. Put the symbols right on the page for them between the text boxes, and/or label them clearly. The biggest inconvienance is that they have to press TAB between each section of the number to move from textbox to textbox. Add another textbox for "Extension" if you think that might be necessary.Then, store your data in 3 (or 4) columns in the database, with each part of the phone number broken out (area code / exchange / number -- and/or extension as well). Now, you have good data, no symbols, no parsing, and you can easily output or format those parts into a phone number any way you want. And each part is easy to validate as well.- Jeff |
 |
|
|