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

javascript 常用验证 _转转转

s代码

  1. ////----------------Author?Teng------------- ??
  2. //验证是否为空 ??
  3. function ?check_blank(obj,?obj_name){??
  4. ??????if (obj.value?!=? '' ){?????
  5. ????????????return ? true ;?????
  6. ?????}else {?????
  7. ?????????alert(obj_name?+?"所填不能为空!" );???
  8. ?????????obj.value?=?"" ;??
  9. ?????????return ? false ;?????
  10. ?????}?????
  11. }??
  12. ??
  13. //过滤输入字符的长度 ??
  14. function ?check_str_len(name,obj,maxLength){?????
  15. ????obj.value=obj.value.replace(/(^\s*)|(\s*$)/g,?"" );??
  16. ????var ?newvalue?=?obj.value.replace(/[^\x00-\xff]/g,? "**" );???
  17. ????var ?length11?=?newvalue.length;???
  18. ????if (length11>maxLength){??
  19. ????????alert(name+"的长度不能超过" +maxLength+ "个字符!" );??
  20. ????????obj.value="" ;??
  21. ????????obj.focus();???????
  22. ????}???
  23. ?}??
  24. ??
  25. //验证只能为数字 ??
  26. function ?checkNumber(obj){??
  27. ????var ?reg?=?/^[0-9]+$/;??
  28. ????if (obj.value!= "" &&!reg.test(obj.value)){??
  29. ????????alert('只能输入数字!' );??
  30. ????????obj.value?=?"" ;??
  31. ????????obj.focus();??
  32. ????????return ? false ;??
  33. ????}??
  34. }??
  35. ??
  36. //验证数字大小的范围 ??
  37. ??
  38. function ?check_num_value(obj_name,obj,minvalue,maxvalue){??
  39. ????var ?reg?=?/^[0-9]+$/;??
  40. ????if (obj.value!= "" &&!reg.test(obj.value)){??
  41. ????????alert(obj_name+'只能输入数字!' );??
  42. ????????obj.value?=?"" ;??
  43. ????????obj.focus();??
  44. ????????return ? false