hyljava

          #

          Hibernate中用逆轉工程實現多對多關系映射


          history中的c_id與s_id分別是外鍵。
          在hibernate中用myeclicpse逆轉工程實現的多對多


          將 CourseDAO 中的save方法 改成:
           public void save(Course transientInstance) {
            log.debug("saving Course instance");
            Session session=null;
            Transaction tx=null;
            try {
             session=getSession();
             tx=session.beginTransaction();
             
             
             session.save(transientInstance);
             tx.commit();
             log.debug("save successful");
            } catch (RuntimeException re) {
             log.error("save failed", re);
             if(tx!=null){
              tx.rollback();
             }
             throw re;
            }
           }
          將 Student DAO 中的save方法 改成:

          public void save(Student transientInstance) {
            log.debug("saving Student instance");
            Session session=null;
            Transaction tx=null;
            try {
             session=getSession();
             tx=session.beginTransaction();
             
             session.save(transientInstance);
             log.debug("save successful");
            } catch (RuntimeException re) {
             log.error("save failed", re);
             if(tx!=null){
              tx.rollback();
             }
             throw re;
            }
           }
          將 HistoryDAO 中的save方法 改成:

          public void save(History transientInstance) {
            log.debug("saving History instance");
            Session session=null;
            Transaction tx=null;
            try {
             session=getSession();
             tx=session.beginTransaction();
             session.save(transientInstance);
             tx.commit();
             log.debug("save successful");
            } catch (RuntimeException re) {
             log.error("save failed", re);
             if(tx!=null){
              tx.rollback();
             }
             throw re;
            }
           }
          測試類如下:

          public class Test {

          public static void main(String[] args) {
              Course course=new Course();
              CourseDAO cdao=new CourseDAO();
            
            Student stu=new Student();
            StudentDAO sdao=new StudentDAO();
              
            History his=new History();
            HistoryId hid=new HistoryId();
            HistoryDAO hdao=new HistoryDAO();
            
            
              course.setCName("c++");
              course.setCTer("張三");
            
            stu.setSName("張同學");
            stu.setSAge(22);
            
            hid.setCourse(course);
            hid.setStudent(stu);
             
             his.setId(hid);
                cdao.save(course);
             sdao.save(stu);
             hdao.save(his);
            }

          }


          posted @ 2012-05-13 18:04 何云隆 閱讀(250) | 評論 (0)編輯 收藏

          解決URL傳非英文、數字亂碼問題

           
          <script language="javascript">
                          var name1=encodeURI("<%=name%>");
                    var name2=encodeURI(name1);
                 window.location.href="qnaWrite.jsp?qname="+name2;
          </script>

          接收頁面:
          <%
                      String   name=java.net.URLDecoder.decode(request.getParameter("qname"),"utf-8");
           %>

          posted @ 2012-05-11 16:40 何云隆 閱讀(235) | 評論 (0)編輯 收藏

          Oracle啟動(停止)服務腳本

          net start OracleServiceORCL
          net start OracleOraDb10g_home1TNSListener
          net start OracleDBConsoleorcl

          net stop OracleServiceORCL
          net stop OracleOraDb10g_home1TNSListener
          net stop OracleDBConsoleorcl

          posted @ 2012-05-04 15:48 何云隆 閱讀(236) | 評論 (0)編輯 收藏

          驗證身份證的工具類(10、15、18位身份證號都能驗證出性別,省份、、、)

          import java.text.ParseException;
          import java.text.SimpleDateFormat;
          import java.util.Calendar;
          import java.util.Date;
          import java.util.HashMap;
          import java.util.Map;

          import org.apache.commons.lang.StringUtils;

          /**
           * 身份證工具類
           *
           * @author June
           * @version 1.0, 2010-06-17
           */
          public class IdcardUtils extends StringUtils {

              /** 中國公民身份證號碼最小長度。 */
              public static final int CHINA_ID_MIN_LENGTH = 15;

              /** 中國公民身份證號碼最大長度。 */
              public static final int CHINA_ID_MAX_LENGTH = 18;

              /** 省、直轄市代碼表 */
              public static final String cityCode[] = {
                      "11", "12", "13", "14", "15", "21", "22", "23", "31", "32", "33", "34", "35", "36", "37", "41",
                      "42", "43", "44", "45", "46", "50", "51", "52", "53", "54", "61", "62", "63", "64", "65", "71",
                      "81", "82", "91"
              };

              /** 每位加權因子 */
              public static final int power[] = {
                      7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2
              };

              /** 第18位校檢碼 */
              public static final String verifyCode[] = {
                      "1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"
              };
              /** 最低年限 */
              public static final int MIN = 1930;
              public static Map<String, String> cityCodes = new HashMap<String, String>();
              /** 臺灣身份首字母對應數字 */
              public static Map<String, Integer> twFirstCode = new HashMap<String, Integer>();
              /** 香港身份首字母對應數字 */
              public static Map<String, Integer> hkFirstCode = new HashMap<String, Integer>();
              static {
                  cityCodes.put("11", "北京");
                  cityCodes.put("12", "天津");
                  cityCodes.put("13", "河北");
                  cityCodes.put("14", "山西");
                  cityCodes.put("15", "內蒙古");
                  cityCodes.put("21", "遼寧");
                  cityCodes.put("22", "吉林");
                  cityCodes.put("23", "黑龍江");
                  cityCodes.put("31", "上海");
                  cityCodes.put("32", "江蘇");
                  cityCodes.put("33", "浙江");
                  cityCodes.put("34", "安徽");
                  cityCodes.put("35", "福建");
                  cityCodes.put("36", "江西");
                  cityCodes.put("37", "山東");
                  cityCodes.put("41", "河南");
                  cityCodes.put("42", "湖北");
                  cityCodes.put("43", "湖南");
                  cityCodes.put("44", "廣東");
                  cityCodes.put("45", "廣西");
                  cityCodes.put("46", "海南");
                  cityCodes.put("50", "重慶");
                  cityCodes.put("51", "四川");
                  cityCodes.put("52", "貴州");
                  cityCodes.put("53", "云南");
                  cityCodes.put("54", "西藏");
                  cityCodes.put("61", "陜西");
                  cityCodes.put("62", "甘肅");
                  cityCodes.put("63", "青海");
                  cityCodes.put("64", "寧夏");
                  cityCodes.put("65", "新疆");
                  cityCodes.put("71", "臺灣");
                  cityCodes.put("81", "香港");
                  cityCodes.put("82", "澳門");
                  cityCodes.put("91", "國外");
                  twFirstCode.put("A", 10);
                  twFirstCode.put("B", 11);
                  twFirstCode.put("C", 12);
                  twFirstCode.put("D", 13);
                  twFirstCode.put("E", 14);
                  twFirstCode.put("F", 15);
                  twFirstCode.put("G", 16);
                  twFirstCode.put("H", 17);
                  twFirstCode.put("J", 18);
                  twFirstCode.put("K", 19);
                  twFirstCode.put("L", 20);
                  twFirstCode.put("M", 21);
                  twFirstCode.put("N", 22);
                  twFirstCode.put("P", 23);
                  twFirstCode.put("Q", 24);
                  twFirstCode.put("R", 25);
                  twFirstCode.put("S", 26);
                  twFirstCode.put("T", 27);
                  twFirstCode.put("U", 28);
                  twFirstCode.put("V", 29);
                  twFirstCode.put("X", 30);
                  twFirstCode.put("Y", 31);
                  twFirstCode.put("W", 32);
                  twFirstCode.put("Z", 33);
                  twFirstCode.put("I", 34);
                  twFirstCode.put("O", 35);
                  hkFirstCode.put("A", 1);
                  hkFirstCode.put("B", 2);
                  hkFirstCode.put("C", 3);
                  hkFirstCode.put("R", 18);
                  hkFirstCode.put("U", 21);
                  hkFirstCode.put("Z", 26);
                  hkFirstCode.put("X", 24);
                  hkFirstCode.put("W", 23);
                  hkFirstCode.put("O", 15);
                  hkFirstCode.put("N", 14);
              }

              /**
               * 將15位身份證號碼轉換為18位
               *
               * @param idCard
               *            15位身份編碼
               * @return 18位身份編碼
               */
              public static String conver15CardTo18(String idCard) {
                  String idCard18 = "";
                  if (idCard.length() != CHINA_ID_MIN_LENGTH) {
                      return null;
                  }
                  if (isNum(idCard)) {
                      // 獲取出生年月日
                      String birthday = idCard.substring(6, 12);
                      Date birthDate = null;
                      try {
                          birthDate = new SimpleDateFormat("yyMMdd").parse(birthday);
                      } catch (ParseException e) {
                          e.printStackTrace();
                      }
                      Calendar cal = Calendar.getInstance();
                      if (birthDate != null)
                          cal.setTime(birthDate);
                      // 獲取出生年(完全表現形式,如:2010)
                      String sYear = String.valueOf(cal.get(Calendar.YEAR));
                      idCard18 = idCard.substring(0, 6) + sYear + idCard.substring(8);
                      // 轉換字符數組
                      char[] cArr = idCard18.toCharArray();
                      if (cArr != null) {
                          int[] iCard = converCharToInt(cArr);
                          int iSum17 = getPowerSum(iCard);
                          // 獲取校驗位
                          String sVal = getCheckCode18(iSum17);
                          if (sVal.length() > 0) {
                              idCard18 += sVal;
                          } else {
                              return null;
                          }
                      }
                  } else {
                      return null;
                  }
                  return idCard18;
              }

              /**
               * 驗證身份證是否合法
               */
              public static boolean validateCard(String idCard) {
                  String card = idCard.trim();
                  if (validateIdCard18(card)) {
                      return true;
                  }
                  if (validateIdCard15(card)) {
                      return true;
                  }
                  String[] cardval = validateIdCard10(card);
                  if (cardval != null) {
                      if (cardval[2].equals("true")) {
                          return true;
                      }
                  }
                  return false;
              }

              /**
               * 驗證18位身份編碼是否合法
               *
               * @param idCard 身份編碼
               * @return 是否合法
               */
              public static boolean validateIdCard18(String idCard) {
                  boolean bTrue = false;
                  if (idCard.length() == CHINA_ID_MAX_LENGTH) {
                      // 前17位
                      String code17 = idCard.substring(0, 17);
                      // 第18位
                      String code18 = idCard.substring(17, CHINA_ID_MAX_LENGTH);
                      if (isNum(code17)) {
                          char[] cArr = code17.toCharArray();
                          if (cArr != null) {
                              int[] iCard = converCharToInt(cArr);
                              int iSum17 = getPowerSum(iCard);
                              // 獲取校驗位
                              String val = getCheckCode18(iSum17);
                              if (val.length() > 0) {
                                  if (val.equalsIgnoreCase(code18)) {
                                      bTrue = true;
                                  }
                              }
                          }
                      }
                  }
                  return bTrue;
              }

              /**
               * 驗證15位身份編碼是否合法
               *
               * @param idCard
               *            身份編碼
               * @return 是否合法
               */
              public static boolean validateIdCard15(String idCard) {
                  if (idCard.length() != CHINA_ID_MIN_LENGTH) {
                      return false;
                  }
                  if (isNum(idCard)) {
                      String proCode = idCard.substring(0, 2);
                      if (cityCodes.get(proCode) == null) {
                          return false;
                      }
                      String birthCode = idCard.substring(6, 12);
                      Date birthDate = null;
                      try {
                          birthDate = new SimpleDateFormat("yy").parse(birthCode.substring(0, 2));
                      } catch (ParseException e) {
                          e.printStackTrace();
                      }
                      Calendar cal = Calendar.getInstance();
                      if (birthDate != null)
                          cal.setTime(birthDate);
                      if (!valiDate(cal.get(Calendar.YEAR), Integer.valueOf(birthCode.substring(2, 4)),
                              Integer.valueOf(birthCode.substring(4, 6)))) {
                          return false;
                      }
                  } else {
                      return false;
                  }
                  return true;
              }

              /**
               * 驗證10位身份編碼是否合法
               *
               * @param idCard 身份編碼
               * @return 身份證信息數組
               *         <p>
               *         [0] - 臺灣、澳門、香港 [1] - 性別(男M,女F,未知N) [2] - 是否合法(合法true,不合法false)
               *         若不是身份證件號碼則返回null
               *         </p>
               */
              public static String[] validateIdCard10(String idCard) {
                  String[] info = new String[3];
                  String card = idCard.replaceAll("[\\(|\\)]", "");
                  if (card.length() != 8 && card.length() != 9 && idCard.length() != 10) {
                      return null;
                  }
                  if (idCard.matches("^[a-zA-Z][0-9]{9}$")) { // 臺灣
                      info[0] = "臺灣";
                      System.out.println("11111");
                      String char2 = idCard.substring(1, 2);
                      if (char2.equals("1")) {
                          info[1] = "M";
                          System.out.println("MMMMMMM");
                      } else if (char2.equals("2")) {
                          info[1] = "F";
                          System.out.println("FFFFFFF");
                      } else {
                          info[1] = "N";
                          info[2] = "false";
                          System.out.println("NNNN");
                          return info;
                      }
                      info[2] = validateTWCard(idCard) ? "true" : "false";
                  } else if (idCard.matches("^[1|5|7][0-9]{6}\\(?[0-9A-Z]\\)?$")) { // 澳門
                      info[0] = "澳門";
                      info[1] = "N";
                      // TODO
                  } else if (idCard.matches("^[A-Z]{1,2}[0-9]{6}\\(?[0-9A]\\)?$")) { // 香港
                      info[0] = "香港";
                      info[1] = "N";
                      info[2] = validateHKCard(idCard) ? "true" : "false";
                  } else {
                      return null;
                  }
                  return info;
              }

              /**
               * 驗證臺灣身份證號碼
               *
               * @param idCard
               *            身份證號碼
               * @return 驗證碼是否符合
               */
              public static boolean validateTWCard(String idCard) {
                  String start = idCard.substring(0, 1);
                  String mid = idCard.substring(1, 9);
                  String end = idCard.substring(9, 10);
                  Integer iStart = twFirstCode.get(start);
                  Integer sum = iStart / 10 + (iStart % 10) * 9;
                  char[] chars = mid.toCharArray();
                  Integer iflag = 8;
                  for (char c : chars) {
                      sum = sum + Integer.valueOf(c + "") * iflag;
                      iflag--;
                  }
                  return (sum % 10 == 0 ? 0 : (10 - sum % 10)) == Integer.valueOf(end) ? true : false;
              }

              /**
               * 驗證香港身份證號碼(存在Bug,部份特殊身份證無法檢查)
               * <p>
               * 身份證前2位為英文字符,如果只出現一個英文字符則表示第一位是空格,對應數字58 前2位英文字符A-Z分別對應數字10-35
               * 最后一位校驗碼為0-9的數字加上字符"A","A"代表10
               * </p>
               * <p>
               * 將身份證號碼全部轉換為數字,分別對應乘9-1相加的總和,整除11則證件號碼有效
               * </p>
               *
               * @param idCard 身份證號碼
               * @return 驗證碼是否符合
               */
              public static boolean validateHKCard(String idCard) {
                  String card = idCard.replaceAll("[\\(|\\)]", "");
                  Integer sum = 0;
                  if (card.length() == 9) {
                      sum = (Integer.valueOf(card.substring(0, 1).toUpperCase().toCharArray()[0]) - 55) * 9
                              + (Integer.valueOf(card.substring(1, 2).toUpperCase().toCharArray()[0]) - 55) * 8;
                      card = card.substring(1, 9);
                  } else {
                      sum = 522 + (Integer.valueOf(card.substring(0, 1).toUpperCase().toCharArray()[0]) - 55) * 8;
                  }
                  String mid = card.substring(1, 7);
                  String end = card.substring(7, 8);
                  char[] chars = mid.toCharArray();
                  Integer iflag = 7;
                  for (char c : chars) {
                      sum = sum + Integer.valueOf(c + "") * iflag;
                      iflag--;
                  }
                  if (end.toUpperCase().equals("A")) {
                      sum = sum + 10;
                  } else {
                      sum = sum + Integer.valueOf(end);
                  }
                  return (sum % 11 == 0) ? true : false;
              }

              /**
               * 將字符數組轉換成數字數組
               *
               * @param ca
               *            字符數組
               * @return 數字數組
               */
              public static int[] converCharToInt(char[] ca) {
                  int len = ca.length;
                  int[] iArr = new int[len];
                  try {
                      for (int i = 0; i < len; i++) {
                          iArr[i] = Integer.parseInt(String.valueOf(ca[i]));
                      }
                  } catch (NumberFormatException e) {
                      e.printStackTrace();
                  }
                  return iArr;
              }

              /**
               * 將身份證的每位和對應位的加權因子相乘之后,再得到和值
               *
               * @param iArr
               * @return 身份證編碼。
               */
              public static int getPowerSum(int[] iArr) {
                  int iSum = 0;
                  if (power.length == iArr.length) {
                      for (int i = 0; i < iArr.length; i++) {
                          for (int j = 0; j < power.length; j++) {
                              if (i == j) {
                                  iSum = iSum + iArr[i] * power[j];
                              }
                          }
                      }
                  }
                  return iSum;
              }

              /**
               * 將power和值與11取模獲得余數進行校驗碼判斷
               *
               * @param iSum
               * @return 校驗位
               */
              public static String getCheckCode18(int iSum) {
                  String sCode = "";
                  switch (iSum % 11) {
                  case 10:
                      sCode = "2";
                      break;
                  case 9:
                      sCode = "3";
                      break;
                  case 8:
                      sCode = "4";
                      break;
                  case 7:
                      sCode = "5";
                      break;
                  case 6:
                      sCode = "6";
                      break;
                  case 5:
                      sCode = "7";
                      break;
                  case 4:
                      sCode = "8";
                      break;
                  case 3:
                      sCode = "9";
                      break;
                  case 2:
                      sCode = "x";
                      break;
                  case 1:
                      sCode = "0";
                      break;
                  case 0:
                      sCode = "1";
                      break;
                  }
                  return sCode;
              }

              /**
               * 根據身份編號獲取年齡
               *
               * @param idCard
               *            身份編號
               * @return 年齡
               */
              public static int getAgeByIdCard(String idCard) {
                  int iAge = 0;
                  if (idCard.length() == CHINA_ID_MIN_LENGTH) {
                      idCard = conver15CardTo18(idCard);
                  }
                  String year = idCard.substring(6, 10);
                  Calendar cal = Calendar.getInstance();
                  int iCurrYear = cal.get(Calendar.YEAR);
                  iAge = iCurrYear - Integer.valueOf(year);
                  return iAge;
              }

              /**
               * 根據身份編號獲取生日
               *
               * @param idCard 身份編號
               * @return 生日(yyyyMMdd)
               */
              public static String getBirthByIdCard(String idCard) {
                  Integer len = idCard.length();
                  if (len < CHINA_ID_MIN_LENGTH) {
                      return null;
                  } else if (len == CHINA_ID_MIN_LENGTH) {
                      idCard = conver15CardTo18(idCard);
                  }
                  return idCard.substring(6, 14);
              }

              /**
               * 根據身份編號獲取生日年
               *
               * @param idCard 身份編號
               * @return 生日(yyyy)
               */
              public static Short getYearByIdCard(String idCard) {
                  Integer len = idCard.length();
                  if (len < CHINA_ID_MIN_LENGTH) {
                      return null;
                  } else if (len == CHINA_ID_MIN_LENGTH) {
                      idCard = conver15CardTo18(idCard);
                  }
                  return Short.valueOf(idCard.substring(6, 10));
              }

              /**
               * 根據身份編號獲取生日月
               *
               * @param idCard
               *            身份編號
               * @return 生日(MM)
               */
              public static Short getMonthByIdCard(String idCard) {
                  Integer len = idCard.length();
                  if (len < CHINA_ID_MIN_LENGTH) {
                      return null;
                  } else if (len == CHINA_ID_MIN_LENGTH) {
                      idCard = conver15CardTo18(idCard);
                  }
                  return Short.valueOf(idCard.substring(10, 12));
              }

              /**
               * 根據身份編號獲取生日天
               *
               * @param idCard
               *            身份編號
               * @return 生日(dd)
               */
              public static Short getDateByIdCard(String idCard) {
                  Integer len = idCard.length();
                  if (len < CHINA_ID_MIN_LENGTH) {
                      return null;
                  } else if (len == CHINA_ID_MIN_LENGTH) {
                      idCard = conver15CardTo18(idCard);
                  }
                  return Short.valueOf(idCard.substring(12, 14));
              }

              /**
               * 根據身份編號獲取性別
               *
               * @param idCard 身份編號
               * @return 性別(M-男,F-女,N-未知)
               */
              public static String getGenderByIdCard(String idCard) {
                  String sGender = "N";
                  if (idCard.length() == CHINA_ID_MIN_LENGTH) {
                      idCard = conver15CardTo18(idCard);
                  }
                  String sCardNum = idCard.substring(16, 17);
                  if (Integer.parseInt(sCardNum) % 2 != 0) {
                      sGender = "男";
                  } else {
                      sGender = "女";
                  }
                  return sGender;
              }

              /**
               * 根據身份編號獲取戶籍省份
               *
               * @param idCard 身份編碼
               * @return 省級編碼。
               */
              public static String getProvinceByIdCard(String idCard) {
                  int len = idCard.length();
                  String sProvince = null;
                  String sProvinNum = "";
                  if (len == CHINA_ID_MIN_LENGTH || len == CHINA_ID_MAX_LENGTH) {
                      sProvinNum = idCard.substring(0, 2);
                  }
                  sProvince = cityCodes.get(sProvinNum);
                  return sProvince;
              }

              /**
               * 數字驗證
               *
               * @param val
               * @return 提取的數字。
               */
              public static boolean isNum(String val) {
                  return val == null || "".equals(val) ? false : val.matches("^[0-9]*$");
              }

              /**
               * 驗證小于當前日期 是否有效
               *
               * @param iYear
               *            待驗證日期(年)
               * @param iMonth
               *            待驗證日期(月 1-12)
               * @param iDate
               *            待驗證日期(日)
               * @return 是否有效
               */
              public static boolean valiDate(int iYear, int iMonth, int iDate) {
                  Calendar cal = Calendar.getInstance();
                  int year = cal.get(Calendar.YEAR);
                  int datePerMonth;
                  if (iYear < MIN || iYear >= year) {
                      return false;
                  }
                  if (iMonth < 1 || iMonth > 12) {
                      return false;
                  }
                  switch (iMonth) {
                  case 4:
                  case 6:
                  case 9:
                  case 11:
                      datePerMonth = 30;
                      break;
                  case 2:
                      boolean dm = ((iYear % 4 == 0 && iYear % 100 != 0) || (iYear % 400 == 0))
                              && (iYear > MIN && iYear < year);
                      datePerMonth = dm ? 29 : 28;
                      break;
                  default:
                      datePerMonth = 31;
                  }
                  return (iDate >= 1) && (iDate <= datePerMonth);
              }
          }

          posted @ 2012-04-26 18:26 何云隆 閱讀(1077) | 評論 (0)編輯 收藏

          js表單驗證控制代碼

           

          /*

          目錄:

          1:js 字符串長度限制、判斷字符長度 、js限制輸入、限制不能輸入、textarea 長度限制

          2.:js判斷漢字、判斷是否漢字 、只能輸入漢字

          3:js判斷是否輸入英文、只能輸入英文

          4:js只能輸入數字,判斷數字、驗證數字、檢測數字、判斷是否為數字、只能輸入數字

          5:只能輸入英文字符和數字

          6: js email驗證 、js 判斷email 、信箱/郵箱格式驗證

          7:js字符過濾,屏蔽關鍵字

          8:js密碼驗證、判斷密碼

          2.1: js 不為空、為空或不是對象 、判斷為空 、判斷不為空

          2.2:比較兩個表單項的值是否相同

          2.3:表單只能為數字和"_",

          2.4:表單項輸入數值/長度限定

          2.5:中文/英文/數字/郵件地址合法性判斷

          2.6:限定表單項不能輸入的字符

          2.7表單的自符控制

          1. 檢查一段字符串是否全由數字組成

          2. 怎么判斷是否是字符

          3. 怎么判斷是否含有漢字

          4. 郵箱格式驗證

          5. 數字格式驗證

          6. 電話號碼格式驗證

          7. 判斷輸入是否為中文的函數

          8. 綜合的判斷用戶輸入的合法性的函數

          9. 判斷密碼是否輸入一致

          10. 判斷用戶名是否為數字字母下滑線

          2.8:form文本域的通用校驗函數

          */

          1. 長度限制

          <script>

          function test()

          {

          if(document.a.b.value.length>50)

          {

          alert("不能超過50個字符!");

          document.a.b.focus();

          return false;

          }

          }

          </script>

          <form name=a onsubmit="return test()">

          <textarea name="b" cols="40" wrap="VIRTUAL" rows="6"></textarea>

          <input type="submit" name="Submit" value="check">

          </form>

           

          2. 只能是漢字

          <input onkeyup="value="/oblog/value.replace(/[^\u4E00-\u9FA5]/g,'')">

           

          3." 只能是英文

          <script language=javascript>

          function onlyEng()

          {

          if(!(event.keyCode>=65&&event.keyCode<=90))

          event.returnvalue=false;

          }

          </script>

           

          <input onkeydown="onlyEng();">

           

          4. 只能是數字

          <script language=javascript>

          function onlyNum()

          {

          if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105)))

          //考慮小鍵盤上的數字鍵

          event.returnvalue=false;

          }

          </script>

           

          <input onkeydown="onlyNum();">

           

          5. 只能是英文字符和數字

          <input onkeyup="value="/oblog/value.replace(/[\W]/g,"'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">

           

          6. 驗證油箱格式

          <SCRIPT LANGUAGE=javascript RUNAT=Server>

          function isEmail(strEmail) {

          if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)

          return true;

          else

          alert("oh");

          }

          </SCRIPT>

          <input type=text onblur=isEmail(this.value)>

           

          7. 屏蔽關鍵字(這里屏蔽***和****)

          <script language="javascript1.2">

          function test() {

          if((a.b.value.indexOf ("***") == 0)||(a.b.value.indexOf ("****") == 0)){

          alert(":)");

          a.b.focus();

          return false;}

          }

          </script>

          <form name=a onsubmit="return test()">

          <input type=text name=b>

          <input type="submit" name="Submit" value="check">

          </form>

           

          8. 兩次輸入密碼是否相同

          <FORM METHOD=POST ACTION="">

          <input type="password" id="input1">

          <input type="password" id="input2">

          <input type="button" value="test" onclick="check()">

          </FORM>

          <script>

          function check()

          {

          with(document.all){

          if(input1.value!=input2.value)

          {

          alert("false")

          input1.value = "";

          input2.value = "";

          }

          else document.forms[0].submit();

          }

          }

          </script>

          夠了吧 :)

          屏蔽右鍵 很酷

          oncontextmenu="return false" ondragstart="return false" onselectstart="return false"

          加在body中

           

           

           

          2.1 表單項不能為空

           

          <script language="javascript">

          <!--

          function CheckForm()

          {

          if (document.form.name.value.length == 0) {

          alert("請輸入您姓名!");

          document.form.name.focus();

          return false;

          }

          return true;

          }

          -->

          </script>

           

          2.2 比較兩個表單項的值是否相同

           

          <script language="javascript">

          <!--

          function CheckForm()

          if (document.form.PWD.value != document.form.PWD_Again.value) {

          alert("您兩次輸入的密碼不一樣!請重新輸入.");

          document.ADDUser.PWD.focus();

          return false;

          }

          return true;

          }

          -->

          </script>

           

          2.3 表單項只能為數字和"_",用于電話/銀行帳號驗證上,可擴展到域名注冊等

           

          <script language="javascript">

          <!--

          function isNumber(String)

          {

          var Letters = "1234567890-"; //可以自己增加可輸入值

          var i;

          var c;

          if(String.charAt( 0 )=='-')

          return false;

          if( String.charAt( String.length - 1 ) == '-' )

          return false;

          for( i = 0; i < String.length; i ++ )

          {

          c = String.charAt( i );

          if (Letters.indexOf( c ) < 0)

          return false;

          }

          return true;

          }

          function CheckForm()

          {

          if(! isNumber(document.form.TEL.value)) {

          alert("您的電話號碼不合法!");

          document.form.TEL.focus();

          return false;

          }

          return true;

          }

          -->

          </script>

           

           

          2.4 表單項輸入數值/長度限定

           

          <script language="javascript">

          <!--

          function CheckForm()

          {

          if (document.form.count.value > 100 || document.form.count.value < 1)

          {

          alert("輸入數值不能小于零大于100!");

          document.form.count.focus();

          return false;

          }

          if (document.form.MESSAGE.value.length<10)

          {

          alert("輸入文字小于10!");

          document.form.MESSAGE.focus();

          return false;

          }

          return true;

          }

          //-->

          </script>

           

          2.5 中文/英文/數字/郵件地址合法性判斷

           

          <SCRIPT LANGUAGE="javascript">

          <!--

           

          function isEnglish(name) //英文值檢測

          {

          if(name.length == 0)

          return false;

          for(i = 0; i < name.length; i++) {

          if(name.charCodeAt(i) > 128)

          return false;

          }

          return true;

          }

           

          function isChinese(name) //中文值檢測

          {

          if(name.length == 0)

          return false;

          for(i = 0; i < name.length; i++) {

          if(name.charCodeAt(i) > 128)

          return true;

          }

          return false;

          }

           

          function isMail(name) // E-mail值檢測

          {

          if(! isEnglish(name))

          return false;

          i = name.indexOf(" at ");

          j = name dot lastIndexOf(" at ");

          if(i == -1)

          return false;

          if(i != j)

          return false;

          if(i == name dot length)

          return false;

          return true;

          }

           

          function isNumber(name) //數值檢測

          {

          if(name.length == 0)

          return false;

          for(i = 0; i < name.length; i++) {

          if(name.charAt(i) < "0" || name.charAt(i) > "9")

          return false;

          }

          return true;

          }

           

          function CheckForm()

          {

          if(! isMail(form.Email.value)) {

          alert("您的電子郵件不合法!");

          form.Email.focus();

          return false;

          }

          if(! isEnglish(form.name.value)) {

          alert("英文名不合法!");

          form.name.focus();

          return false;

          }

          if(! isChinese(form.cnname.value)) {

          alert("中文名不合法!");

          form.cnname.focus();

          return false;

          }

          if(! isNumber(form.PublicZipCode.value)) {

          alert("郵政編碼不合法!");

          form.PublicZipCode.focus();

          return false;

          }

          return true;

          }

          //-->

          </SCRIPT>

           

          2.6 限定表單項不能輸入的字符

           

          <script language="javascript">

          <!--

           

          function contain(str,charset)// 字符串包含測試函數

          {

          var i;

          for(i=0;i<charset.length;i++)

          if(str.indexOf(charset.charAt(i))>=0)

          return true;

          return false;

          }

           

          function CheckForm()

          {

          if ((contain(document.form.NAME.value, "%\(\)><")) || (contain(document.form.MESSAGE.value, "%\(\)><")))

          {

          alert("輸入了非法字符");

          document.form.NAME.focus();

          return false;

          }

          return true;

          }

          //-->

          </script>

           

          1. 檢查一段字符串是否全由數字組成

          ---------------------------------------

          <script language="Javascript"><!--

          function checkNum(str){return str.match(/\D/)==null}

          alert(checkNum("1232142141"))

          alert(checkNum("123214214a1"))

          // --></script>

           

          2. 怎么判斷是否是字符

          ---------------------------------------

          if (/[^\x00-\xff]/g.test(s)) alert("含有漢字");

          else alert("全是字符");

           

          3. 怎么判斷是否含有漢字

          ---------------------------------------

          if (escape(str).indexOf("%u")!=-1) alert("含有漢字");

          else alert("全是字符");

           

          4. 郵箱格式驗證

          ---------------------------------------

          //函數名:chkemail

          //功能介紹:檢查是否為Email Address

          //參數說明:要檢查的字符串

          //返回值:0:不是 1:是

          function chkemail(a)

          { var i=a.length;

          var temp = a.indexOf('@');

          var tempd = a.indexOf('.');

          if (temp > 1) {

          if ((i-temp) > 3){

          if ((i-tempd)>0){

          return 1;

          }

           

          }

          }

          return 0;

          }

           

          5. 數字格式驗證

          ---------------------------------------

          //函數名:fucCheckNUM

          //功能介紹:檢查是否為數字

          //參數說明:要檢查的數字

          //返回值:1為是數字,0為不是數字

          function fucCheckNUM(NUM)

          {

          var i,j,strTemp;

          strTemp="0123456789";

          if ( NUM.length== 0)

          return 0

          for (i=0;i<NUM.length;i++)

          {

          j=strTemp.indexOf(NUM.charAt(i));

          if (j==-1)

          {

          //說明有字符不是數字

          return 0;

          }

          }

          //說明是數字

          return 1;

          }

           

          6. 電話號碼格式驗證

          ---------------------------------------

          //函數名:fucCheckTEL

          //功能介紹:檢查是否為電話號碼

          //參數說明:要檢查的字符串

          //返回值:1為是合法,0為不合法

          function fucCheckTEL(TEL)

          {

          var i,j,strTemp;

          strTemp="0123456789-()# ";

          for (i=0;i<TEL.length;i++)

          {

          j=strTemp.indexOf(TEL.charAt(i));

          if (j==-1)

          {

          //說明有字符不合法

          return 0;

          }

          }

          //說明合法

          return 1;

          }

           

          7. 判斷輸入是否為中文的函數

          ---------------------------------------

          function ischinese(s){

          var ret=true;

          for(var i=0;i<s.length;i++)

          ret=ret && (s.charCodeAt(i)>=10000);

          return ret;

          }

           

          8. 綜合的判斷用戶輸入的合法性的函數

          ---------------------------------------

          <script language="javascript">

          //限制輸入字符的位數開始

          //m是用戶輸入,n是要限制的位數

          function issmall(m,n)

          {

          if ((m<n) && (m>0))

          {

          return(false);

          }

          else

          {return(true);}

          }

           

          9. 判斷密碼是否輸入一致

          ---------------------------------------

          function issame(str1,str2)

          {

          if (str1==str2)

          {return(true);}

          else

          {return(false);}

          }

           

          10. 判斷用戶名是否為數字字母下滑線

          ---------------------------------------

          function notchinese(str){

          var reg=/[^A-Za-z0-9_]/g

          if (reg.test(str)){

          return (false);

          }else{

          return(true); }

          }

           

          2.8. form文本域的通用校驗函數

          ---------------------------------------

          作用:檢測所有必須非空的input文本,比如姓名,賬號,郵件地址等等。

          該校驗現在只針對文本域,如果要針對form里面的其他域對象,可以改變判斷條件。

           

          使用方法:在要檢測的文本域中加入title文字。文字是在提示信息,你要提示給用戶的該字段的中文名。比如要檢測用戶名

          html如下<input name="txt_1" title="姓名">,當然,最好用可視化工具比如dreamweaver什么的來編輯域。

          如果要檢測數字類型數據的話,再把域的id統一為sz.

          javascript判斷日期類型比較麻煩,所以就沒有做日期類型校驗的程序了.高手可以補充。

           

          程序比較草,只是提供一個思路。拋磚引玉! :)

          哦,對了,函數調用方法:< form onsubmit="return dovalidate()">

           

          function dovalidate()

          {

          fm=document.forms[0] //只檢測一個form,如果是多個可以改變判斷條件

          for(i=0;i<fm.length;i++)

          {

          //檢測判斷條件,根據類型不同可以修改

          if(fm[i].tagName.toUpperCase()=="INPUT" &&fm[i].type.toUpperCase()=="TEXT" && (fm[i].title!=""))

           

          if(fm[i].value="/blog/="")//

          {

          str_warn1=fm[i].title+"不能為空!";

          alert(str_warn1);

          fm[i].focus();

          return false;

          }

          if(fm[i].id.toUpperCase()=="SZ")//數字校驗

          {

          if(isNaN(fm[i].value))

          { str_warn2=fm[i].title+"格式不對";

          alert(str_warn2);

          fm[i].focus();

          return false;

          }

          }

          }

          return true;

          }

          posted @ 2012-04-23 20:02 何云隆 閱讀(242) | 評論 (0)編輯 收藏

          Linux從圖形界面切換到命令行

          Redhat Linux9, Ctl + Alt + F1~F6, 都可以直接進入命令行界面。Ctl + Alt + F7 可以返回圖形界面。

          posted @ 2012-04-22 12:47 何云隆 閱讀(219) | 評論 (0)編輯 收藏

          執行MysqL命令出現中文顯示亂碼

          在命令行輸入
          set name gb2312

          posted @ 2012-04-22 12:44 何云隆 閱讀(194) | 評論 (0)編輯 收藏

          Linux 下的命令

               摘要: 一、安裝和登陸命令1、進入圖形界面startx 2、進入圖形界面init 5 3、進入字符界面init 3 4、登陸login 5、關機poweroff-p 關閉機器的時候關閉電源-n 在關閉機器時不同步數據-w 不做關機的操作,只是把這個操作記錄到日志里-d 不把關機的信息記錄到日志文件里-f 不調用shutdown ...  閱讀全文

          posted @ 2012-04-22 12:39 何云隆 閱讀(298) | 評論 (0)編輯 收藏

          僅列出標題
          共11頁: First 上一頁 3 4 5 6 7 8 9 10 11 
          主站蜘蛛池模板: 镇沅| 乌拉特后旗| 霍林郭勒市| 平阳县| 昔阳县| 酉阳| 吴江市| 丰都县| SHOW| 柘荣县| 洪雅县| 临城县| 无棣县| 南溪县| 楚雄市| 景洪市| 沾益县| 商洛市| 沧州市| 滦南县| 星座| 尼木县| 夏河县| 东方市| 蒲江县| 厦门市| 宝坻区| 宁城县| 榆林市| 连平县| 眉山市| 永和县| 象州县| 屏东县| 潮州市| 雷山县| 临城县| 无棣县| 仙桃市| 泸定县| 锦屏县|