/** * 字符串的相关操作 */ import {isNull, isUndefined} from "util"; export class StringUtils{ public static isEmpty(str: string){ if(isUndefined(str)){ return true; } if(isNull(str)){ return true; } if(str.trim().length === 0){ return true; } return false; } public static isPhone(phone: string){ if(this.isEmpty(phone)){ return false; } //通过正则表达式判断手机号码格式是否正确,根据电信,联通、移动手机号码规则可以到以下正则 // 手机号码第一位是[1]开头,第二位[3,4,5,7,8]中的一位,第三位到第十一位则是[0-9]中的数字; //^1表示开头为1 //[3|4|5|7|8] 表示3、4、5、7、8中的一位数值 //[0-9]{9} 匹配包含0-9的数字 let reg = /^1[3|4|5|7|8][0-9]{9}/; if(reg.test(phone)){ return true;//手机号码正确 } return false; } }