473,378 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

formatting TextBox.Text

347 100+
I have a web page that will be supplying data to a sql query and I want my users to type in dates as mm/dd/yyyy but my sql query needs the dates as yyyy/dd/mm. How can I reformat the textbox.text to reflect that re-formatting of the data?

Thank you

Doug
Mar 22 '11 #1

✓ answered by Marknut

First things first, here’s an option for your problem:

Add a RegularExpressionValidator using this ValidationExpression: “^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$”

From this webpage: http://www.regxlib.com/DisplayPatter...4&categoryId=5.

CroCrew is right, be careful when building dynamic sql with open user input. With a RegularExpressionValidator, and some validating on the server-side, you can secure your application and limit the formatting on the front end. The security concern is mainly that someone can enter an apostrophe and interject their own code into your sql, so make sure that you verify that the data is actually a date using IsDate(TextBox_Date) for extra security.

3 2389
CroCrew
564 Expert 512MB
You may have heard it, or you may haven't, but dynamic SQL is not good practice. I don’t want to get into it but you can goggle “Why Dynamic SQL is Bad” and find out yourself.

CroCrew~
Mar 23 '11 #2
Marknut
42
First things first, here’s an option for your problem:

Add a RegularExpressionValidator using this ValidationExpression: “^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$”

From this webpage: http://www.regxlib.com/DisplayPatter...4&categoryId=5.

CroCrew is right, be careful when building dynamic sql with open user input. With a RegularExpressionValidator, and some validating on the server-side, you can secure your application and limit the formatting on the front end. The security concern is mainly that someone can enter an apostrophe and interject their own code into your sql, so make sure that you verify that the data is actually a date using IsDate(TextBox_Date) for extra security.
May 9 '11 #3
dougancil
347 100+
CroCrew and Mark,

Thank you both for the input on this topic. I decided to go against this methodology and use regularexpressionvalidators to control what the user could input. As this is currently only an internal facing web site, the security restrictions are pretty lax but it's also good to know about the issues that reside with dynamic sql.
May 10 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Alpha | last post by:
Hi, I have a window based program. One of the form has several textboxes and a datagrid. The textboxes are bind to the same dataset table as the datagrid and the text changes to reflect different...
5
by: Steve S | last post by:
Heres what I want to do...User types into a texbox, clicks a button, the button saves that text to a file. The problem is that when I click the submit button, any changes made to the textbox are...
1
by: Carlo | last post by:
Hi How do I get textbox text to be formatted on the fly as entering. I have a textbox which will hold numerics larger than a million which I want to autoformat i.e FormatNumber, so that it makes...
2
by: jason | last post by:
hello. i am just trying to save a TextBox.Text value to a database, but strangely, when the value is changed on the web form, the changes are not recognized in the event where i try to save the...
3
by: Henry Lee | last post by:
Hi, I want to tell if the .NET textbox.text control on the web page has been input or not So I write If TextBox.Text <> "" then ..... End IF But you know it does not work , the error "'text'...
0
by: d.steininger | last post by:
Hi there! Is there a way to bind a Textbox.Text to a ScrollBar.Value (not the Textbox-own Scrollbar) and vice versa? The Problem: I have to deal with two controls. The Textbox should accept...
3
by: Owen Richardson | last post by:
I have read several posts regarding formatting multiline text for rendering becuase vbCrLf needs to be converted to <br/tags, and i need to do the same. My question is the best way to achieve this...
18
by: obrienkev | last post by:
Hi, I have a multiline TextBox. Text contained in the TextBox will be stored in a SQL Server Database. How do I format the textBox correctly for database entry? e.g. How do I ensure that new...
5
montzter
by: montzter | last post by:
Hi evryone, I'm having trouble in formatting the inputed data in the text box so that everytime user lost focus it will adjust its value to contain the format (#,####.##). ie user will input...
6
by: Andy B | last post by:
I need to take the value of a textbox and format it in a more readable date. How do you do this? I tried textbox.text.tostring("date format string") but the compiler doesnt like that idea... any...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.