// 电子邮件验证
function checkEmail(theField) {
var pattern = /^.+@.+\..+$/;
if(theField.value == "") return true;
if (!pattern.test(theField.value)) {
alert("请输入合法的电子邮件地址");
theField.focus();
theField.select();
return false;
}
return true;
}
// 是否为只读域(如file,text等域只接受右边按钮选择传回的结果)
function checkReadField() {
alert("请点击后面的图标进行选择");
// this.blur();
}
/*
* RoundTo(Digit,How):数值格式化函数,Digit要格式化的数字,How要保留的小数位数。
*/
function RoundTo(Digit,How)
{
Digit = Math.round(Digit*Math.pow(10,How))/Math.pow(10,How);
return Digit;
}
//去除字符串的前后空格
String.prototype.trim = function()
{
return this.replace(/(^\s+)|\s+$/g,"");
}
//将指定的字段转换为大写
function UpperCase(theField){
theField.value = theField.value.toUpperCase();
}
//将指定的字段转换为小写
function LowerCase(theField){
theField.value = theField.value.toLowerCase();
}
//比较两个时间大小,相等或第二个大返回true,第一个大返回false.
//现在只支持2005-12-30或2005-12-30 10:00:00的时间格式
function DateCompare(theField1,fieldName1,theField2,fieldName2)
{
var d1 = theField1.value;
var d2 = theField2.value;
if (d1==d2) return true; // 相等
var a1 = null;var a2 = null;
var b1 = null;var b2 = null;
if (d1.length==10){
d1 += " 00:00:00";
}
a1=d1.substring(0,10).split("-");
a2=d1.substring(11).split(":");
if (d2.length==10){
d2 += " 00:00:00";
}
b1=d2.substring(0,10).split("-");
b2=d2.substring(11).split(":");
for (i=0;i<3;i++){
if( a1[i].charAt(0) == '0' ) { a1[i] = a1[i].substring(1,2); }
if( b1[i].charAt(0) == '0' ) { b1[i] = b1[i].substring(1,2); }
if (parseInt(a1[i])>parseInt(b1[i])){
alert(fieldName1+"不能大于"+fieldName2);
return false;
}
if (parseInt(a1[i])<parseInt(b1[i])){
return true;
}
}
for (i=0;i<3;i++){
if( a2[i].charAt(0) == '0' ) { a2[i] = a2[i].substring(1,2); }
if( b2[i].charAt(0) == '0' ) { b2[i] = b2[i].substring(1,2); }
if (parseInt(a2[i])>parseInt(b2[i])){
alert(fieldName1+"不能大于"+fieldName2);
return false;
}
if (parseInt(a2[i])<parseInt(b2[i])){
return true;
}
}
}
//将给定的字符串中的&字符替换成@@
function ConvertStr(s){
var i;
var s2 = s;
while(s2.indexOf("&")>0){
i = s2.indexOf("&");
s2 = s2.substring(0, i) + "@@" + s2.substring(i + 1, s2.length);
}
return s2;
}
//将给定的字符串中的@@字符替换成&
function ReConvertStr(s){
var i;
var s2 = s;
while(s2.indexOf("@@")>0){
i = s2.indexOf("@@");
s2 = s2.substring(0, i) + "&" + s2.substring(i + 2, s2.length);
}
return s2;
}
//将给定的字符串中的单双引号转义
function ForamtValue(oStr)
{
switch(typeof(oStr))
{
case "date" :
//直接toString()转换,可以加入丰富的显示方式
sStr = (new Date(oStr)).toString();
break;
default :
sStr = String(oStr);
}
sStr = sStr.replace(/\"/g,"""); //输入框中显示双引号问题
sStr = sStr.replace(/\'/g,"'"); //输入框中显示单引号问题
return sStr;
}
|