common.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //用于未来扩展的提示正确错误的JS
  2. $.showErr = function(str,func)
  3. {
  4. $.weeboxs.open(str, {boxid:'msg_box',contentType:'text',showButton:true, showCancel:false, showOk:true,title:'错误',width:250,type:'wee',onclose:func});
  5. };
  6. $.showSuccess = function(str,func)
  7. {
  8. $.weeboxs.open(str, {boxid:'msg_box',contentType:'text',showButton:true, showCancel:false, showOk:true,title:'提示',width:250,type:'wee',onclose:func});
  9. };
  10. $.showCfm = function(str,funo,func)
  11. {
  12. $.weeboxs.open(str, {boxid:'msg_box',contentType:'text',showButton:true, showCancel:true, showOk:true,title:'确认',width:250,type:'wee',onok:funo,onclose:func});
  13. };
  14. /*验证*/
  15. $.minLength = function(value, length , isByte) {
  16. var strLength = $.trim(value).length;
  17. if(isByte)
  18. strLength = $.getStringLength(value);
  19. return strLength >= length;
  20. };
  21. $.maxLength = function(value, length , isByte) {
  22. var strLength = $.trim(value).length;
  23. if(isByte)
  24. strLength = $.getStringLength(value);
  25. return strLength <= length;
  26. };
  27. $.getStringLength=function(str)
  28. {
  29. str = $.trim(str);
  30. if(str=="")
  31. return 0;
  32. var length=0;
  33. for(var i=0;i <str.length;i++)
  34. {
  35. if(str.charCodeAt(i)>255)
  36. length+=2;
  37. else
  38. length++;
  39. }
  40. return length;
  41. };
  42. $.checkMobilePhone = function(value){
  43. /*if($.trim(value)!='')
  44. return /^\d{6,}$/i.test($.trim(value));
  45. else
  46. return true;*/
  47. var reg1 = /^(13[0-9]|145|147|15[0-3]|15[5-9]|18[0-9])[0-9]{8}$/;
  48. var reg2 = /^(\([0-9]{3,4}\)|[0-9]{3,4}\-)[0-9]{7,8}$/;
  49. var reg3 = /^[0-9]{7,8}$/;
  50. var str = $.trim(value);
  51. if (!reg1.test(str) && !reg2.test(str) && !reg3.test(str)) {
  52. return false;
  53. }
  54. else{
  55. return true;
  56. }
  57. };
  58. $.checkEmail = function(val){
  59. var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
  60. return reg.test(val);
  61. };