日期:2014-05-16  浏览次数:20399 次

js 验证非常好_转

http://justshare.iteye.com/blog/226479

?

  1. //the?common?event,If?your?brower?is?firefox,you?should?use?this?function?instead?of?"window.event" ??
  2. ????function?getEvent()?{??
  3. ????????if (document.all)???
  4. ????????????return ?window.event;? //get?ie?event ??
  5. ????????func=getEvent.caller;??
  6. ????????while (func!= null )?{??
  7. ????????????var?arg0=func.arguments[0 ]; //alert(arg0); ??
  8. ????????????if (arg0)?{??
  9. ????????????????if ((arg0.constructor==Event?||?arg0.constructor?==MouseEvent)?||?(typeof(arg0)== "object" ?&&?arg0.preventDefault?&&?arg0.stopPropagation))?{??
  10. ????????????????????return ?arg0;??
  11. ????????????????}?????????????
  12. ????????????}??
  13. ????????????func=func.caller;??
  14. ????????}??
  15. ????????return ? null ;??
  16. ????}??
  17. ????//去除左侧空格??? ??
  18. ????function?LTrim(str)?????
  19. ????{?????
  20. ?????return ?str.replace(/^\s*/g, "" );?????
  21. ????}??????
  22. ????????
  23. ????//去右空格??? ??
  24. ????function?RTrim(str)?????
  25. ????{?????
  26. ????return ?str.replace(/\s*$/g, "" );?????
  27. ????}?????
  28. ???????
  29. ???//去掉字符串两端的空格??? ??
  30. ???function?trim(str)?????
  31. ???{?????
  32. ????return ?str.replace(/(^\s*)|(\s*$)/g,? "" );??????
  33. ???}?????
  34. ??????
  35. ??//去除字符串中间空格??? ??
  36. ???function?CTim(str)?????
  37. ???{?????
  38. ????return ?str.replace(/\s/g, '' );?????
  39. ???}?????
  40. ??????
  41. ???//是否为由数字组成的字符串??? ??
  42. ???function?is_digitals(str)?????
  43. ??{?????
  44. ????var?reg=/^[0 - 9 ]*$/; //匹配整数??? ??
  45. ???return ?reg.test(str);???????????
  46. ???}?????
  47. ???????
  48. ???//验证是否为整数,包括正负数;??? ??
  49. ???fun