String.prototype.Trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function()
{
return this.replace(/(^\s*)/g, "");
}
String.prototype.RTrim = function()
{
return this.replace(/(\s*$)/g, "");
}
/*********************************************************************************
* FUNCTION: isInt
* PARAMETER: theStr AS String
* RETURNS: TRUE if the passed parameter is an integer, otherwise FALSE
* CALLS: isDigit
**********************************************************************************/
function isInt (theStr) {
var flag = true;
if (isEmpty(theStr)) { flag=false; }
else
{ for (var i=0; i<theStr.length; i++) {
if (isDigit(theStr.substring(i,i+1)) == false) {
flag = false; break;
}
}
}
return(flag);
}
/*********************************************************************************
* FUNCTION: isBetween
* PARAMETERS: val AS any value
* lo AS Lower limit to check
* hi AS Higher limit to check
* CALLS: NOTHING
* RETURNS: TRUE if val is between lo and hi both inclusive, otherwise false.
**********************************************************************************/
function isBetween (val, lo, hi) {
if ((val < lo) || (val > hi)) { return(false); }
else { return(true); }
}
/*********************************************************************************
* FUNCTION: isDate checks a valid date
* PARAMETERS: theStr AS String
* CALLS: isBetween, isInt
* RETURNS: TRUE if theStr is a valid date otherwise false.
**********************************************************************************/
function isDate (theStr) {
var the1st = theStr.indexOf('-');
var the2nd = theStr.lastIndexOf('-');
if (the1st == the2nd) { return(false); }
else {
var y = theStr.substring(0,the1st);
var m = theStr.substring(the1st+1,the2nd);
var d = theStr.substring(the2nd+1,theStr.length);
var maxDays = 31;
if (isInt(m)==false || isInt(d)==false || isInt(y)==false) {
return(false); }
else if (y.length < 4) { return(false); }
else if (!isBetween (m, 1, 12)) { return(false); }
else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;
else if (m==2) {
if (y % 4 > 0) maxDays = 28;
else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;
else maxDays = 29;
}
if (isBetween(d, 1, maxDays) == false) { return(false); }
else { return(true); }
}
}
/*********************************************************************************
* FUNCTION: isEuDate checks a valid date in British format
* PARAMETERS: theStr AS String
* CALLS: isBetween, isInt
* RETURNS: TRUE if theStr is a valid date otherwise false.
**********************************************************************************/
function isEuDate (theStr) {
if (isBetween(theStr.length, 8, 10) == false) { return(false); }
else {
var the1st = theStr.indexOf('/');
var the2nd = theStr.lastIndexOf('/');
if (the1st == the2nd) { return(false); }
else {
var m = theStr.substring(the1st+1,the2nd);
var d = theStr.substring(0,the1st);
var y = theStr.substring(the2nd+1,theStr.length);
var maxDays = 31;
if (isInt(m)==false || isInt(d)==false || isInt(y)==false) {
return(false); }
else if (y.length < 4) { return(false); }
else if (isBetween (m, 1, 12) == false) { return(false); }
else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;
else if (m==2) {
if (y % 4 > 0) maxDays = 28;
else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;
else maxDays = 29;
}
if (isBetween(d, 1, maxDays) == false) { return(false); }
else { return(true); }
}
}
}
/********************************************************************************
* FUNCTION: Compare Date! Which is the latest!
* PARAMETERS: lessDate,moreDate AS String
* CALLS: isDate,isBetween
* RETURNS: TRUE if lessDate<moreDate
*********************************************************************************/
function isComdate (lessDate , moreDate)
{
if (!isDate(lessDate)) { return(false);}
if (!isDate(moreDate)) { return(false);}
var less1st = lessDate.indexOf('-');
var less2nd = lessDate.lastIndexOf('-');
var more1st = moreDate.indexOf('-');
var more2nd = moreDate.lastIndexOf('-');
var lessy = lessDate.substring(0,less1st);
var lessm = lessDate.substring(less1st+1,less2nd);
var lessd = lessDate.substring(less2nd+1,lessDate.length);
var morey = moreDate.substring(0,more1st);
var morem = moreDate.substring(more1st+1,more2nd);
var mored = moreDate.substring(more2nd+1,moreDate.length);
var Date1 = new Date(lessy,lessm,lessd);
var Date2 = new Date(morey,morem,mored);
if (Date1>Date2) { return(false);}
return(true);
}
/*********************************************************************************
* FUNCTION isEmpty checks if the parameter is empty or null
* PARAMETER str AS String
**********************************************************************************/
function isEmpty (str) {
if ((str==null)||(str.length==0)) return true;
else return(false);
}
/*********************************************************************************
* FUNCTION: isReal
* PARAMETER: heStr AS String
decLen AS Integer (how many digits after period)
* RETURNS: TRUE if theStr is a float, otherwise FALSE
* CALLS: isInt
**********************************************************************************/
function isReal (theStr, decLen) {
var dot1st = theStr.indexOf('.');
var dot2nd = theStr.lastIndexOf('.');
var OK = true;
if (isEmpty(theStr)) return false;
if (dot1st == -1) {
if (!isInt(theStr)) return(false);
else return(true);
}
else if (dot1st != dot2nd) return (false);
else if (dot1st==0) return (false);
else {
var intPart = theStr.substring(0, dot1st);
var decPart = theStr.substring(dot2nd+1);
if (decPart.length > decLen) return(false);
else if (!isInt(intPart) || !isInt(decPart)) return (false);
else if (isEmpty(decPart)) return (false);
else return(true);
}
}
/*********************************************************************************
* FUNCTION: isEmail
* PARAMETER: String (Email Address)
* RETURNS: TRUE if the String is a valid Email address
* FALSE if the passed string is not a valid Email Address
* EMAIL FORMAT: AnyName@EmailServer e.g; webmaster@hotmail.com
* @ sign can appear only once in the email address.
*********************************************************************************/
function isStrEmail (s) {
var patrn=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
if (!patrn.exec(s)){
s.value='';
alert('请输入正确的邮件地址!');
return false;
}
return true;
}
/*********************************************************************************
* FUNCTION: newWindow
* PARAMETERS: doc -> Document to open in the new window
hite -> Height of the new window
wide -> Width of the new window
bars -> 1-Scroll bars = YES 0-Scroll Bars = NO
resize -> 1-Resizable = YES 0-Resizable = NO
* CALLS: NONE
* RETURNS: New window instance
**********************************************************************************/
function newWindow (doc, hite, wide, bars, resize) {
var winNew="_blank";
var opt="toolbar=0,location=0,directories=0,status=0,menubar=0,";
opt+=("scrollbars="+bars+",");
opt+=("resizable="+resize+",");
opt+=("width="+wide+",");
opt+=("height="+hite);
winHandle=window.open(doc,winNew,opt);
return;
}
/*********************************************************************************
* FUNCTION: DecimalFormat
* PARAMETERS: paramValue -> Field value
* CALLS: NONE
* RETURNS: Formated string
**********************************************************************************/
function DecimalFormat (paramValue) {
var intPart = parseInt(paramValue);
var decPart =parseFloat(paramValue) - intPart;
str = "";
if ((decPart == 0) || (decPart == null)) str += (intPart + ".00");
else str += (intPart + decPart);
return (str);
}
/*********************************************************************************
* EO_JSLib.js
* javascript正则表达式检验
**********************************************************************************/
//校验是否全由数字组成
function isDigit(s)
{
var patrn=/^[0-9]{1,20}$/;
if (!patrn.exec(s.value)){
s.value='';
alert('请输入数字!');
return false;
}
return true;
}
//校验登录名:只能输入5-20个以字母开头、可带数字、“_”、“.”的字串
function isRegisterUserName(s)
{
var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;
if (!patrn.exec(s)) return false
return true
}
//校验用户姓名:只能输入1-30个以字母开头的字串
function isTrueName(s)
{
var patrn=/^[a-zA-Z]{1,30}$/;
if (!patrn.exec(s)) return false
return true
}
//校验密码:只能输入6-20个字母、数字、下划线
function isPasswd(s)
{
var patrn=/^(\w){6,20}$/;
if (!patrn.exec(s)) return false
return true
}
//校验普通电话、传真号码:可以“+”开头,除数字外,可含有“-”
function isTel(s)
{
//var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?(\d){1,12})+$/;
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
if (!patrn.exec(s)) return false
return true
}
//普通电话、传真号码验证
function checkTel(obj){
var str = obj.value;
if(str==""){
return true;
}
if(isTel(str)){
return true;
} else {
obj.focus();
return false;
}
}
//校验手机号码:必须以数字开头,除数字外,可含有“-”
function isMobil(s)
{
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
if (!patrn.exec(s))
{
alert("手机号码格式不对");
return false;
}
return true;
}
//校验邮政编码
function isPostalCode(obj)
{
var s=obj.value;
if(s==""){
return true;
}
//var patrn=/^[a-zA-Z0-9]{3,12}$/;
var patrn=/^[a-zA-Z0-9 ]{3,12}$/;
if (!patrn.exec(s)) {
alert("邮政编码格式不对!");
obj.focus();
return false;
}
return true;
}
function isIP(s) //by zergling
{
var patrn=/^[0-9.]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}
/********************************************************************************
* FUNCTION: Compare Date! Which is the latest!
* PARAMETERS: lessDate,moreDate AS String
* CALLS: isDate,isBetween
* RETURNS: TRUE if lessDate<moreDate
* while return false alert errmsg
*********************************************************************************/
function isComdateMsg (lessDate1 ,startstr, moreDate1,endstr){
var re =/\./g;
var lessDate = lessDate1.replace(re,"-");
var moreDate = moreDate1.replace(re,"-");
var re1 =/\\/g;
var lessDate = lessDate.replace(re1,"-");
var moreDate = moreDate.replace(re1,"-");
if(!isComdate(lessDate,moreDate)){
var err = endstr + "必须大于";
err = err + startstr;
alert(err);
}
return isComdate(lessDate,moreDate);
}
/*
===========================================
//去除前后空格
===========================================
*/
function TrimSpace(str)
{
if(str=="undefined"){
return "";
}
return str.replace(/(^ *)|( *$)/g, "");
}
function need_input(sForm)//通用文本域校验 by l_dragon
{
for(i=0;i<sForm.length;i++)
{
if(sForm[i].tagName.toUpperCase()=="INPUT" &&sForm[i].type.toUpperCase()=="TEXT" && (sForm[i].title!=""))
var ovalue = TrimSpace(sForm[i].value);
if(ovalue=="")//
{
sWarn=sForm[i].title+"不能为空!";
alert(sWarn);
sForm[i].focus();
return false;
}
if(sForm[i].tagName.toUpperCase()=="TEXTAREA" && (sForm[i].title!=""))
if(ovalue=="")//
{
sWarn=sForm[i].title+"不能为空!";
alert(sWarn);
sForm[i].focus();
return false;
}
}
return true;
}
//2, 身份证的验证
function isIdCardNo(num)
{
//if (isNaN(num)) {alert("输入的不是数字!"); return false;}
var len = num.length, re;
if (len == 15)
re = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$/);
else if (len == 18)
re = new RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\d)$/);
else {alert("身份证输入的数字位数不对!"); return false;}
var a = num.match(re);
if (a != null)
{
if (len==15)
{
var D = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]);
var B = D.getYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
}
else
{
var D = new Date(a[3]+"/"+a[4]+"/"+a[5]);
var B = D.getFullYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
}
if (!B) {alert("输入的身份证号 "+ a[0] +" 里出生日期不对!"); return false;}
}
return true;
}
/*
===========================================
3,是否是手机
===========================================
*/
function isMobile(obj)
{
var mobile = obj.value;
if(mobile==""){
return true;
}
//var result = (/^13\d{9}$/g.test(value)||(/^15[0-35-9]\d{8}$/g.test(value))||(/^18[05-9]\d{8}$/g.test(value)));
if(/^13\d{9}$/g.test(mobile)||(/^15[0-35-9]\d{8}$/g.test(mobile))||(/^18[05-9]\d{8}$/g.test(mobile))) {
return true;
}else {
alert("手机输入有误!");
obj.focus();
}
return false;
}
//校验电话号码(同isMobil(s)):必须以数字开头,除数字外,可含有“-”
function isPhone(obj)
{
var s=obj.value;
if(s==""){
return true;
}
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
if (!patrn.exec(s))
{
alert("电话号码格式不对");
obj.focus();
return false;
}
return true;
}
/*
===========================================
4,是否是邮件
===========================================
*/
function isEmail(obj)
{
var email = obj.value;
if(email==""){
return true;
}
var result = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(email);
if(result) {
}else {
alert("邮件地址输入有误!");
obj.focus();
}
}
/*
===========================================
5,是否是邮编(中国)
===========================================
*/
function isZipCode(obj)
{
var ZipCode = obj.value;
if(ZipCode==""){
return true;
}
var result = /^[0-9]{6}$/.test(ZipCode);
if(result) {
}else {
alert("邮编输入有误!");
obj.focus();
}
}
/*
===========================================
选择或者撤销选择所有的checkbox useridcheck
===========================================
*/
function checkall(ck){
var nodes = document.all.useridcheck;
var str="";
if(ck.getAttribute("Checked")){
if(nodes==undefined){ //没有元素
return;
} else if(nodes.length==undefined) { //一个元素
if(nodes.disabled!=true) {
nodes.setAttribute("checked",true);
}
} else { //多个元素
for (i = 0; i < nodes.length; i++) {
var cNode;
cNode=nodes[i];
if(cNode.disabled!=true) {
cNode.setAttribute("checked",true);
}
}
}
}else{
if(nodes==undefined){ //没有元素
return;
} else if(nodes.length==undefined) { //一个元素
if(nodes.disabled!=true) {
nodes.setAttribute("checked",false);
}
} else { //多个元素
for (i = 0; i < nodes.length; i++) {
var cNode;
cNode=nodes[i];
if(cNode.disabled!=true) {
cNode.setAttribute("checked",false);
}
}
}
}
}
/*
===========================================
//特殊字符check
===========================================
*/
function checkspecial(obj){
var str = obj.value;
var SPECIAL_STR = ".。~!@%^&#$*();'\"?><[]{}\\|,:/=+?“”‘ ";
for(i=0;i<str.length;i++) {
if (SPECIAL_STR.indexOf(str.charAt(i)) !=-1){
alert("输入不能含有非法字符("+str.charAt(i)+")!");
obj.focus();
return false;
}
}
return true;
}
/*
===========================================
//textarea check length and special
===========================================
*/
function checktxtlength(obj,len){
var str = obj.value;
if(str.length>len){
obj.value=str.substring(0,len);
return false;
}
var SPECIAL_STR = "~!%^&#$*();'\"?><[]{}\\|,:/=+?“”‘";
for(i=0;i<str.length;i++) {
if (SPECIAL_STR.indexOf(str.charAt(i)) !=-1){
alert("输入不能含有非法字符("+str.charAt(i)+")!");
obj.focus();
return false;
}
}
return true;
}
/*
===========================================
//textarea check length and special
===========================================
*/
function checkcorrect(obj){
if(/[^a-zA-z0-9_]/g.test(obj.value)){
alert("只能是字母或数字,不能含有中文!");
obj.focus();
return false;
}
return checktxtlength(obj,20);
}
function clearpageElements()
{
var Elements = document.getElementsByTagName("input");
var i;
for ( i in Elements ) {
if ( Elements[i].type == "text") {
Elements[i].value = "";
}
}
return true;
}
//通用文本域校验
function pagevalidate(tag)
{
var j = 0;
var blnReturn=true;
for(;j <document.forms.length ; j++){
for (i = 0; i <document.forms[j].length ; i++){
if(document.forms[j].elements[i].name.length>0){
try{
if((document.forms[j].elements[i].type.toUpperCase()=="TEXT"||document.forms[j].elements[i].type.toUpperCase()=="PASSWORD"||document.forms[j].elements[i].type.toUpperCase()=="TEXTAREA"))
{
try{
var strValue = "";
strValue=document.forms[j].elements[i].value;
}catch(e){}
var strCtrlName=document.forms[j].elements[i].title;
if(strValue==""&&strCtrlName!="")
{
sWarn=strCtrlName+"不能为空!";
alert(sWarn,window,document.forms[j].document.all.item(document.forms[j].elements[i].name));
document.forms[j].document.all.item(document.forms[j].elements[i].name).focus();
blnReturn=false;
break;
}
// if(strValue.indexOf("%")>=0||strValue.indexOf("\"")>=0||strValue.indexOf("^")>=0||strValue.indexOf("/")>=0||strValue.indexOf("?")>=0||strValue.indexOf("*")>=0||strValue.indexOf("#")>=0||strValue.indexOf("'")>=0||strValue.indexOf("<")>=0 || strValue.indexOf(">")>=0 ||strValue.indexOf("&")>=0||strValue.indexOf("'//")>=0||strValue.indexOf("';")>=0 || strValue.indexOf("//")>=0||strValue.indexOf("\\")>=0)
if(strValue.indexOf("%")>=0||strValue.indexOf("\"")>=0||strValue.indexOf("^")>=0||strValue.indexOf("?")>=0||strValue.indexOf("*")>=0||strValue.indexOf("#")>=0||strValue.indexOf("'")>=0||strValue.indexOf("<")>=0 || strValue.indexOf(">")>=0 ||strValue.indexOf("&")>=0||strValue.indexOf("'//")>=0||strValue.indexOf("';")>=0 || strValue.indexOf("//")>=0||strValue.indexOf("\\")>=0)
{
if(strCtrlName!=null && strCtrlName!="")
{
alert(strCtrlName+ "中含有%、';、//、'//、\"、#、*、^、?、/、\"、<、>、\'、\\、&\"非法字符,请重新输入!",window,document.forms[j].document.all.item(document.forms[j].elements[i].name));
document.forms[j].document.all.item(document.forms[j].elements[i].name).focus();
}
else
{
alert("页面信息中不能含有%、';、//、'//、\"、#、*、^、?、/、\"、<、>、\'、\\、&\"非法字符,请重新输入!",window,document.forms[j].document.all.item(document.forms[j].elements[i].name));
document.forms[j].document.all.item(document.forms[j].elements[i].name).focus();
}
blnReturn=false;
break;
}
if(strValue.length>document.forms[j].elements[i].maxLength){
sWarn=strCtrlName+"超出最大长度["+document.forms[j].elements[i].maxLength+"]";
alert(sWarn,window,document.forms[j].document.all.item(document.forms[j].elements[i].name));
document.forms[j].document.all.item(document.forms[j].elements[i].name).focus();
blnReturn=false;
break;
}
if(strValue.length>0){
document.forms[j].elements[i].value=document.forms[j].elements[i].value.trim();
}
}
if((document.forms[j].elements[i].type.toUpperCase()=="SELECT-ONE"))
{
try{
var strValue = "";
strValue=document.forms[j].elements[i].options[document.forms[j].elements[i].selectedIndex].value;
}catch(e){}
var strCtrlName=document.forms[j].elements[i].title;
if(strValue==""&&strCtrlName!="")
{
sWarn=strCtrlName+"不能为空!";
alert(sWarn,window,document.forms[j].document.all.item(document.forms[j].elements[i].name));
document.forms[j].document.all.item(document.forms[j].elements[i].name).focus();
blnReturn=false;
break;
}
}
if(document.forms[j].elements[i].type.toUpperCase()=="TEXTAREA"){
try{
var strValue = "";
strValue=document.forms[j].elements[i].value;
}catch(e){}
var strCtrlName=document.forms[j].elements[i].title;
if(strValue==""&&strCtrlName!="")
{
sWarn=strCtrlName+"不能为空!";
alert(sWarn,window,document.forms[j].document.all.item(document.forms[j].elements[i].name));
document.forms[j].document.all.item(document.forms[j].elements[i].name).focus();
blnReturn=false;
break;
}
}
}catch(e){}
}
}
return blnReturn;
}
}
function getQueryString(queryStringName)
{
var returnValue="";
var URLString=new String(document.location);
var serachLocation=-1;
var queryStringLength=queryStringName.length;
do
{
serachLocation=URLString.indexOf(queryStringName+"\=");
if (serachLocation!=-1)
{
if ((URLString.charAt(serachLocation-1)=='?') || (URLString.charAt(serachLocation-1)=='&'))
{
URLString=URLString.substr(serachLocation);
break;
}
URLString=URLString.substr(serachLocation+queryStringLength+1);
}
}
while (serachLocation!=-1)
if (serachLocation!=-1)
{
var seperatorLocation=URLString.indexOf("&");
if (seperatorLocation==-1)
{
returnValue=URLString.substr(queryStringLength+1);
}
else
{
returnValue=URLString.substring(queryStringLength+1,seperatorLocation);
}
}
return returnValue;
}
function getUrlSuffix()
{
var txt = document.location.href;
txt = txt.substring(0,txt.indexOf("/EHR/"));
return txt;
}
//数字判断
function IsNum(theField)
{
if (!IsNum2(theField.value))
{
alert("该区域只能输入数字!");
theField.value ="";
return false;
}
return true;
}
function IsNum2(s)
{
var Number = "0123456789";
for (i = 0; i < s.length;i++)
{
// Check that current character isn't whitespace.
var c = s.charAt(i);
if (Number.indexOf(c) == -1) return false;
}
return true
}
function over(obj){
//alert(obj);
obj.style.background='#fefdae';
}
function out(obj){
obj.style.background='#fff';
}
function moveOut(obj){
//alert(obj);
obj.style.background='#f9fdff';
}