1. //校验(国内)邮政编码  
  2. function isPostalCode(codestr){  
  3.     var pattern = /^[0-9]{6}$/;  
  4.     if (trim(codestr) != "") {  
  5.         if (!pattern.exec(codestr)) {  
  6.             return false;  
  7.         }  
  8.         else {  
  9.             return true;  
  10.         }  
  11.     }  
  12. }  
  13.  
  14. /**校验手机号码格式是否正确(15、13、18开头,位数为11位)  
  15.  *  
  16.  * @param {Object} object  
  17.  */ 
  18. function isMobile(phone){  
  19.     var reg0 = /^13\d{5,9}$/;  
  20.     var reg1 = /^15\d{5,9}$/;  
  21.     var reg2 = /^18\d{5,9}$/;  
  22.     var my = false;  
  23.     if (reg0.test(phone)) {  
  24.         my = true;  
  25.     }  
  26.     if (reg1.test(phone)) {  
  27.         my = true;  
  28.     }  
  29.     if (reg2.test(phone)) {  
  30.         my = true;  
  31.     }  
  32.     if (trim(phone) != "") {  
  33.         if (!my) {  
  34.             return false;  
  35.         }  
  36.         else {  
  37.             return true;  
  38.         }  
  39.     }  
  40. }  
  41.  
  42. /**  
  43.  * 判断是否是日期格式(中间必须是'-')  
  44.  * @param  
  45.  */ 
  46. function isDate(datestr){  
  47.     if (trim(datestr) != '') {  
  48.         var patrn = /^(?:(?!0000)[0-9]{4}([-])(?:(?:0?[1-9]|1[0-2])([-])(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])([-])(?:29|30)|(?:0?[13578]|1[02])([-])31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-])0?2([-])29)$/;  
  49.         if (!patrn.exec(obj.value)) {  
  50.             return false;  
  51.         }  
  52.         else {  
  53.             return true;  
  54.         }  
  55.     }  
  56. }  
  57. /**  
  58.  * 判断是email格式是否正确(正确返回true)  
  59.  * @param {Object} strEmail  
  60.  */ 
  61. function isEmail(strEmail){  
  62.     if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)   
  63.         return true;  
  64.     else   
  65.         return false;  
  66. }  
  67.  
  68.  
  69.  /**  
  70.  * js正整数判断(格式正确返回true)  
  71.  * @param {Object} ch  
  72.  */ 
  73. function isNumber(ch){  
  74.     var re = /^\d+$/;  
  75.     if (re.test(ch)) {  
  76.         return true;  
  77.     }  
  78.     return false;  
  79. }  
  80.  
  81.  
  82. /**  
  83.  * js正浮点型数字判断(保留两位小数)(格式正确返回true)  
  84.  * @param {Object} ch  
  85.  */ 
  86. function isFloatNumber(ch){  
  87.     var re = /^\d+(\.\d{1,2})?$/;  
  88.     if (re.test(ch)) {  
  89.         return true;  
  90.     }  
  91.     return false;  
  92. }  
  93.  
  94.  
  95. /**    
  96.  * @desc 验证字符串是否不为空,空格不算字符  
  97.  * @return 不为空返回true,为空返回false  
  98.  */ 
  99. function IfNull(strings){  
  100.     //var strs = /(^\s*|\s*$)/;     
  101.     var str = strings;  
  102.     str = str.replace(/(^\s*)|(\s*$)/g, "");  
  103.     str = str.replace(/(^ *)|( *$)/g, "");  
  104.     if (str == '') {  
  105.         str = "";  
  106.         return str;  
  107.     }  
  108.     return str;