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\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,4}|:)|(?:[a-fA-F\\d]{1,4}:){2}(?:(?::[a-fA-F\\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,5}|:)|(?:[a-fA-F\\d]{1,4}:){1}(?:(?::[a-fA-F\\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,6}|:)|(?::(?:(?::[a-fA-F\\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,7}|:)))(?:%[0-9a-zA-Z]{1,})?$)` , color : `(?:#|0x)(?:[a-f0-9]{3}|[a-f0-9]{6})\\b|(?:rgb|hsl)a?\\([^\\)]*\\)` , chinese : `[\u4e00-\u9fa5]+` } ; function genRegex ( str , flags ? ) { return new RegExp ( `^${ str }$` , flags ) ; } export const REGEX = { num : genRegex ( REGEX_STR . num ) , idCard : genRegex ( REGEX_STR . idCard , 'i' ) , mobile : genRegex ( REGEX_STR . mobile ) , url : genRegex ( REGEX_STR . url ) , ip : genRegex ( REGEX_STR . ip ) , color : genRegex ( REGEX_STR . color ) , chinese : genRegex ( REGEX_STR . chinese ) } ; /**
 * Wheter is number
 *
 * 是否为数字
 */ export function isNum ( value ) { return REGEX . num . test ( value . toString ( ) ) ; } /**
 * Wheter is integer
 *
 * 是否为整数
 */ export function isInt ( value ) { return isNum ( value ) && parseInt ( value . toString ( ) , 10 ) . toString ( ) === value . toString ( ) ; } /**
 * Wheter is decimal
 *
 * 是否为小数点数值
 */ export function isDecimal ( value ) { return isNum ( value ) && ! isInt ( value ) ; } /**
 * Wheter is People's Republic of China identity card
 *
 * 是否为中华人民共和国居民身份证
 */ export function isIdCard ( value ) { return REGEX . idCard . test ( value ) ; } /**
 * Wheter is china mobile (China)
 *
 * 是否为手机号（中国）
 */ export function isMobile ( value ) { return REGEX . mobile . test ( value ) ; } /**
 * Wheter is url address
 *
 * 是否URL地址
 */ export function isUrl ( url ) { return REGEX . url . test ( url ) ; } /**
 * Wheter is IPv4 address (Support v4, v6)
 *
 * 是否IP4地址（支持v4、v6）
 */ export function isIp ( ip ) { return REGEX . ip . test ( ip ) ; } /**
 * Wheter is color
 *
 * 是否颜色代码值
 */ export function isColor ( color ) { return REGEX . color . test ( color ) ; } /**
 * Wheter is chinese
 *
 * 是否中文
 */ export function isChinese ( value ) { return REGEX . chinese . test ( value ) ; }