123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- //验证是否为手机号
- export const CheckPhoneNumber = (number) => {
- let check = /^[1][3,4,5,7,8][0-9]{9}$/;
- if (number.length == 0 || number == null || number.length != 11) {
- return ReturnData(false, '请输入正确的手机号码!');
- } else if (!check.test(number)) {
- // return ReturnData(false, '请输入正确的手机号码!');
- return ReturnData(true, null);
- } else {
- return ReturnData(true, null);
- }
- };
- //验证登录密码
- export const CheckPassword = password => {
- if (password.length == 0 || password == null) {
- return ReturnData(false, '登录密码不允许为空!');
- } else {
- return ReturnData(true, null);
- }
- };
- //返回值通用处理
- export const ReturnData = (status, msg) => {
- return {status: status, msg: msg};
- };
- //四舍五入保留2位小数(不够位数,则用0替补)
- export const RoundingData = (num) => {
- let result = parseFloat(num);
- if (isNaN(result)) {
- console.error('参数非数值,无法四舍五入保留两位小数!');
- return false;
- }
- result = Math.round(num * 100) / 100;
- let s_x = result.toString();
- let pos_decimal = s_x.indexOf('.');
- if (pos_decimal < 0) {
- pos_decimal = s_x.length;
- s_x += '.';
- }
- while (s_x.length <= pos_decimal + 2) {
- s_x += '0';
- }
- return s_x;
- };
- // 四舍五入保留2位小数(不够位数,则用0替补)
- export const NumberTwoDecimal = (number) => {
- let result = parseFloat(number);
- if (isNaN(result)) {
- console.error('参数非数值,无法四舍五入保留两位小数!');
- return '';
- }
- result = Math.round(number * 100) / 100;
- let s_x = result.toString();
- let pos_decimal = s_x.indexOf('.');
- if (pos_decimal < 0) {
- pos_decimal = s_x.length;
- s_x += '.00';
- }
- if (isNaN(result)) {
- return '';
- } else {
- return parseFloat(s_x);
- }
- // while (s_x.length <= pos_decimal + 2) {
- // s_x += '0'
- // }
- };
- // 四舍五入保留10位小数(不够位数,则用0替补)
- export const NumberTenDecimal = (number) => {
- let result = parseFloat(number);
- if (isNaN(result)) {
- console.error('参数非数值,无法四舍五入保留两位小数!');
- return '';
- }
- result = Math.round(number * 10000000000) / 10000000000;
- let s_x = result.toString();
- let pos_decimal = s_x.indexOf('.');
- if (pos_decimal < 0) {
- pos_decimal = s_x.length;
- s_x += '.00';
- }
- // while (s_x.length <= pos_decimal + 10) {
- // s_x += '0'
- // }
- if (isNaN(result)) {
- return '';
- } else {
- return parseFloat(s_x);
- }
- };
- //获取小数位数后6位
- export const GetNum = (num) => {
- let result = parseFloat(num).toString();
- var newNum = result.substring(0, result.indexOf('.') + 7);
- return newNum;
- };
- //检查email是否正确
- export const CheckEmail = (value) => {
- if (
- !/^[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(
- value,
- )
- ) {
- return ReturnData(false, '请输入正确的Email!');
- } else {
- return ReturnData(true, null);
- }
- };
|