Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input mask

Status
Not open for further replies.

tman24m

Programmer
May 21, 2001
93
US
I would like to know how to create a date input text box that has an input mask. I've never done anything with input masks in ASP. Is it possible? Any ideas?

The other option that I'm considering is an auto generated drop down list that is dynamic based on the current system date. This is my answer if I can't get an input mask.
 
After you enter the value you call a javascript function on lostfocus where you format the input and then display it again. I have such a function home, if I don't forget I will copy it here later this day
 
It's pretty long but it a professional one:
sEvent can be Blur or Focus depends when you call the function. Like this
<INPUT id=idCCNumber name=txtCCNumber onBlur=&quot;javascript:formatCCNumber('Blur')&quot; onFocus=&quot;javascript:formatCCNumber('Focus')&quot;>

function formatCCNumber(sEvent)
{
var sValue = document.forms.frmMain.txtCCNumber.value;
var sMaskChar = new String();
var sInputChar = new String();
var sFormattedNumber = new String();
var sFormat = new String();
var i, j;
//CCLength = is the length of the Credit Card Number
if (sValue.length == 0 || <% =CCLength %> ==0)
return;
//sCreditCardMask something like this ###-#####-###
sFormat = &quot;<% =sCreditCardMask %>&quot;


if (sEvent == &quot;Blur&quot;)
{
if (MaskedCreditCard == &quot;True&quot;)
return;
else
{
//verify that the correct number of digits have been entered
if (sValue.length > 0 && sValue.length != <% =CCLength %>)
{
alert('Invalid_credit_card_number')%> ' + <% =CCLength %>);
document.forms.frmMain.txtCCNumber.focus();
document.forms.frmMain.txtCCNumber.select();
return;
}
//Format the credit card number
j = 0;
sFormattedNumber = &quot;&quot;;
for (i=0; i <= sFormat.length; i++)
{
sMaskChar = sFormat.substr(i, 1);
sInputChar = sValue.substr(j, 1);
if (sMaskChar == &quot;#&quot;)
{
//Represents a number, so insert input char
sFormattedNumber = sFormattedNumber + sInputChar;
//Increment input char
j++;
}
else
{
//Represents a space or dash
sFormattedNumber = sFormattedNumber + sMaskChar;
}
}
//Display the formatted number
document.forms.frmMain.txtCCNumber.value = sFormattedNumber;
}
}
else
{
if (sValue.search(&quot;#&quot;) > 0)
{
var theResponse = confirm('Would_you_like_to_enter_a_new');
if (theResponse)
{
MaskedCreditCard = &quot;False&quot;;
sValue = &quot;&quot;;
}
else
{
MaskedCreditCard = &quot;True&quot;;
document.forms.frmMain.txtCCRef.focus();
return;
}
}
sFormattedNumber = &quot;&quot;;
//Strip out dashes and spaces
for (i=0; i < sValue.length; i++)
{
sInputChar = sValue.substr(i, 1);
if (sInputChar >= &quot;0&quot; && sInputChar <= &quot;9&quot;)
sFormattedNumber = sFormattedNumber + sInputChar;
}
//Display the unformatted number
document.forms.frmMain.txtCCNumber.value = sFormattedNumber;
document.forms.frmMain.txtCCNumber.select();
}
}


Hope it will help you,
Regards,
Durug
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top