[使用场景]使用C# 开发掩码输入文本框

更新时间:2014-02-22    来源:Foxpro    手机版     字体:

【www.bbyears.com--Foxpro】

掩码输入是一种常用的控件,我记得第一次看见这种控件是在Visual FoxPro中!感觉功能强,不错。现在用C#开发ASP.NET应用程序也需要用到这种输入的控件,便琢磨着自己做一个。但是由于Visual FoxPro中的掩码文本框功能太强了,一时还不敢去做。网上也有一些自制的如:http://www.weste.net/2004/11-25/09162561988.html,但是感觉功能都不很适合。后来在http://www.stedy.com上看到了他们做的掩码文本框,感觉这种方式在Web应用上很适合,就把客户端代码down下来了!(stedy software 作的是产品,要花钱!而且很贵79.99USD,ft。)
分析了一下stedy的客户端脚本(VBScript)他们为每一种掩码规则都作了一个客户端的方法。如下面是日期掩码格式化的客户端脚本代码:
function maskDate(sValue, sType)
dim zMonth
zMonth = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
if len(trim(sValue)) = 0 then
maskDate = ""
setViewState false
elseif not(isDate(sValue)) then
maskDate = "# INVALID DATE ENTERED #"
setViewState true
else
select case (sType)
case "medium"
maskDate = day(dateValue(sValue)) & "-" & left(zMonth(month(dateValue(sValue)) - 1), 3) & "-" & year(dateValue(sValue))
case "long"
maskDate = zMonth(month(dateValue(sValue)) - 1) & " " & day(dateValue(sValue)) & ", " & year(dateValue(sValue))

本文来源:http://www.bbyears.com/shujuku/4366.html

猜你感兴趣