inspect.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //验证是否为手机号
  2. export const CheckPhoneNumber = (number) => {
  3. let check = /^[1][3,4,5,7,8][0-9]{9}$/;
  4. if (number.length == 0 || number == null || number.length != 11) {
  5. return ReturnData(false, '请输入正确的手机号码!');
  6. } else if (!check.test(number)) {
  7. // return ReturnData(false, '请输入正确的手机号码!');
  8. return ReturnData(true, null);
  9. } else {
  10. return ReturnData(true, null);
  11. }
  12. };
  13. //验证登录密码
  14. export const CheckPassword = password => {
  15. if (password.length == 0 || password == null) {
  16. return ReturnData(false, '登录密码不允许为空!');
  17. } else {
  18. return ReturnData(true, null);
  19. }
  20. };
  21. //返回值通用处理
  22. export const ReturnData = (status, msg) => {
  23. return {status: status, msg: msg};
  24. };
  25. //四舍五入保留2位小数(不够位数,则用0替补)
  26. export const RoundingData = (num) => {
  27. let result = parseFloat(num);
  28. if (isNaN(result)) {
  29. console.error('参数非数值,无法四舍五入保留两位小数!');
  30. return false;
  31. }
  32. result = Math.round(num * 100) / 100;
  33. let s_x = result.toString();
  34. let pos_decimal = s_x.indexOf('.');
  35. if (pos_decimal < 0) {
  36. pos_decimal = s_x.length;
  37. s_x += '.';
  38. }
  39. while (s_x.length <= pos_decimal + 2) {
  40. s_x += '0';
  41. }
  42. return s_x;
  43. };
  44. // 四舍五入保留2位小数(不够位数,则用0替补)
  45. export const NumberTwoDecimal = (number) => {
  46. let result = parseFloat(number);
  47. if (isNaN(result)) {
  48. console.error('参数非数值,无法四舍五入保留两位小数!');
  49. return '';
  50. }
  51. result = Math.round(number * 100) / 100;
  52. let s_x = result.toString();
  53. let pos_decimal = s_x.indexOf('.');
  54. if (pos_decimal < 0) {
  55. pos_decimal = s_x.length;
  56. s_x += '.00';
  57. }
  58. if (isNaN(result)) {
  59. return '';
  60. } else {
  61. return parseFloat(s_x);
  62. }
  63. // while (s_x.length <= pos_decimal + 2) {
  64. // s_x += '0'
  65. // }
  66. };
  67. // 四舍五入保留10位小数(不够位数,则用0替补)
  68. export const NumberTenDecimal = (number) => {
  69. let result = parseFloat(number);
  70. if (isNaN(result)) {
  71. console.error('参数非数值,无法四舍五入保留两位小数!');
  72. return '';
  73. }
  74. result = Math.round(number * 10000000000) / 10000000000;
  75. let s_x = result.toString();
  76. let pos_decimal = s_x.indexOf('.');
  77. if (pos_decimal < 0) {
  78. pos_decimal = s_x.length;
  79. s_x += '.00';
  80. }
  81. // while (s_x.length <= pos_decimal + 10) {
  82. // s_x += '0'
  83. // }
  84. if (isNaN(result)) {
  85. return '';
  86. } else {
  87. return parseFloat(s_x);
  88. }
  89. };
  90. //获取小数位数后6位
  91. export const GetNum = (num) => {
  92. let result = parseFloat(num).toString();
  93. var newNum = result.substring(0, result.indexOf('.') + 7);
  94. return newNum;
  95. };
  96. //检查email是否正确
  97. export const CheckEmail = (value) => {
  98. if (
  99. !/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(
  100. value,
  101. )
  102. ) {
  103. return ReturnData(false, '请输入正确的Email!');
  104. } else {
  105. return ReturnData(true, null);
  106. }
  107. };