newbie questions on TextBox and DateTime

D

Danny Ni

Hi,

I have a TextBox in an aspx form to allow user to enter a date. Say the
TextBox name is txtDate. I have 2 questions:
(1)How do I put today's date as default value?
I tried: txtDate.Text = DateTime.Today.ToString();
I got 4/9/2004 12:00:00 AM, but I don't want the hour part.

(2)How do I do a client side validation that the value user enter is valid?

Thanks in Advance
 
G

Guest

Danny, for question 1, instead use

txtDate.Text = DateTime.Now.ToShortDateString();
 
R

Rick Spiewak

Client side validation has to be done in JavaScript. Use regular
expressions. I don't have a date example, so here's a credit card one:

// Check for credit card valid, indicate failure to user
function validateCC()
{
var lb = document.all.lblInvalidCC;
lb.innerText = "";
if (!isvalidCC())
{
lb.innerText = "Invalid Credit Card Number";
return false;
}
return true;
}

// validate credit card depending on type - any value is OK if no credit
card type is selected
function isvalidCC()
{
var cc = document.all.txtCardNumber.value;
var sValidate = /^.*/;
if (cc !== "")
{
var dl = document.all.dlCreditCardType;
var index = 0;
// Determine selected credit card type by testing all options for
selected
do
{
if (dl.children(index).selected) { break;}
index++;
}
while (index < dl.children.length -1)

// Validate for selected credit card type

switch (dl.children(index).text)
{
case "American Express":
sValidate = /^(3[4,7]\d{2})(-?|\040?)\d{6}(-?|\040?)\d{5}$/;
break;
case "Visa":
sValidate = /^(4\d{3})(-?|\040?)(\d{4}(-?|\040?)){3}$/;
break;
case "MasterCard":
sValidate = /^(5[0-5]\d{2})(-?|\040?)(\d{4}(-?|\040?)){3}$/;
break;
case "Discover":
sValidate = /^(6011)(-?|\040?)(\d{4}(-?|\040?)){3}$/;
break;
default:
sValidate = /^.*/; //No card type selected, don't call it invalid
break;
}
}
return sValidate.test(cc);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top