상용 데이터 형식 검사 및 장치 식별 도구

8869 단어 자바 script
목차
 값 형식 검사
핸드폰 번호 검사
암호 검사
중국어 검사
메 일 박스 검사
검사 장치 시스템 
휴대 전화 장치 인지 검사 하 다.
검 측 ios
안 드 로 이 드 검색 
Mac 검사 계통
Windows 시스템 검색 
Safari 브 라 우 저 검색
플래시 플러그 인 검색
검 측 데이터 형식 
검사 Null
검 측 부정 확
검색 Boolean
검 측 문자열
검사 번호
NaN 검출
검 측 개체
검 측 어 레이
검 측 RegExp
 검 측 지도
검 측 Promise 
검사 날짜
 검출 수학
JSON 검사
기타 
HTML 구조 에서 html 태그 제거
UUID 생 성
시간 처리 장치
 
 값 형식 검사
핸드폰 번호 검사
/**
 *      
 * @param {String | Number} value 
 * @returns {Boolean}
 */
export function isMobile(value) {
    const REG_MOBILE = /^1(3|4|5|6|7|8|9)[0-9]{9}$/
    return REG_MOBILE.test(value)
}

암호 검사
/**
 *     
 * @param {String | Number} value 
 * @returns {Boolean}
 */
export function(value) {
    const REG_PASSWORD = /^[0-9a-zA-Z]{6,20}$/
    return REG_PASSWORD.test(value)
}

중국어 검사
/**
 *       
 * @param {String} value 
 * @returns {Boolean}
 */
export function isChineseString(value) {
    const REG_CHINESE_STRING = /[^(\u4e00-\u9fa5)]{8,24}/
    return REG_CHINESE_STRING.test(value)
}

메 일 박스 검사
/**
 *     
 * @param {String} value 
 * @returns {Boolean}
 */
export function isEmail(value) {
    const REG_EMAIL = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/
    return REG_EMAIL.test(value)
}

검사 장치 시스템 
휴대 전화 장치 인지 검사 하 다.
/**
 *        
 */
export function isMobileDevice() {
    const userAgent = window.navigator.userAgent
    return !!userAgent.match(/AppleWebKit.*Mobile.*/)
}

검 측 ios
/**
 *      IOS  
 */
export function isIOS() {
    const REG_IOS = /iphone|ipad|ipod/
    return REG_IOS.test(userAgent)
}

안 드 로 이 드 검색 
/**
 *       android   
 */
export function isAndroid() {
    const REG_ANFROID = /android/
    return REG_ANFROID.test(userAgent)
}

Mac 검사 계통
/**
 *       MAC   
 */
export function isMac() {
    const REG_MAC = /macintosh|mac os x/i
    return REG_MAC.test(userAgent)
}

Windows 시스템 검색 
/**
 *       WINDOWS   
 */
export function isWindows() {
    const REG_WINDOWS = /windows|win32/i
    return REG_WINDOWS.test(userAgent)
}

Safari 브 라 우 저 검색
/**
 *       Safari    
 */
export function isSafari() {
    const REG_SAFARI = /safari/
    const REG_CHROME = /chrome/
    return REG_SAFARI.test(userAgent) && !REG_CHROME.test(userAgent)
}

플래시 플러그 인 검색
/**
 *             flash   
 *   :
 * 1.           ,     
 * 2.   、  、  Edge、Safari         ActiveXObject,    navigator.plugins       
 * 3. chrome        flash   
 */
export function isFlash() {
    let flash
    if (typeof window.ActiveXObject != 'undefined') {
        flash = window.ActiveXObject('ShockwaveFlash.ShockwaveFlash')
    } else {
        flash = navigator.plugins['Shockwave Flash']
    }
    return flash ? true : false
}

검 측 데이터 형식 
검사 Null
export function isNull(value) {
    const type = Object.prototype.toString
    return type.call(value) === '[object Null]'
}

검 측 부정 확
export function isUndefined(value) {
    const type = Object.prototype.toString
    return type.call(value) === '[object Undefined]'
}

검색 Boolean
export function isBoolean(value) {
    const type = Object.prototype.toString
    return type.call(value) === '[object Boolean]'
}

검 측 문자열
export function isString() {
    const type = Object.prototype.toString
    return type.call(value) === '[object String]'
}

검사 번호
export function isNumber(value) {
    const type = Object.prototype.toString
    return type.call(value) === '[object Number]'
}

NaN 검출
export function isNaN(value) {
    const type = Object.prototype.toString
    return type.call(value) === '[object NaN]'
}

검 측 개체
/**
 *          
 * @param {*} value 
 */
export function isObject(value) {
    const type = Object.prototype.toString
    return type.call(value) === '[object Object]'
}

검 측 어 레이
/**
 *        
 * @param {Array} value
 */
export function isArray (value) {
    const type = Object.prototype.toString
    return type.call(value) === '[object Array]'
}

검 측 RegExp
export function isRegExp(value) {
    const type = Object.prototype.toString
    return type.call(value) === '[object RegExp]'
}

 검 측 지도
export function isMap(value) {
    const type = Object.prototype.toString
    return type.call(value) === '[object Map]'
}

검 측 Promise 
export function isPromise(value) {
    const type = Object.prototype.toString
    return type.call(value) === '[object Promise]'
}

검사 날짜
export function isDate(value) {
    const type = Object.prototype.toString
    reutrn type.call(value) === '[object Date]'
}

 검출 수학
export function isMath(value) {
    const type = Object.prototype.toString
    return type.call(value) === '[object Math]'
}

JSON 검사
export function isJSON(value) {
    const type = Object.prototype.toString
    return type.call(value) === '[object JSON]'
}

검사 오류
export function isError(value) {
    const type = Object.prototype.toString
    return type.call(value) === '[object Error]'
}

 
기타 
HTML 구조 에서 html 태그 제거
/**
 * html     text(   html  )
 * @param {String} value html
 */
export function htmlToText(value) {
    const REG_HTML_TO_TEXT = //g
    return value.replace(REG_HTML_TO_TEXT, '')
}

UUID 생 성
/**
 *   UUID
 */
export function createUuid() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        const r = Math.random() * 16 | 0
        const v = c == 'x' ? r : (r & 0x3 | 0x8)
        return v.toString(16)
    })
}

시간 처리 장치
/**
 *      
 * @param {String} value      
 */
export function moment() {
     var datetime = new Date()
    if (typeof value === 'string' && /^[0-9]{4}(\-|\/)[0-9]{1,2}(\-|\/)[0-9]{1,2}/.test(value)) {
        datetime = new Date(value.replace(/\-/g, '/'))
    } else if (Object.prototype.toString.call(value) === '[object Date]') {
        datetime = value
    }
    
    function repair(value) {
        return value > 9 ? value : `0${value}`
    }

    function format(type) {
        var datetime_format,
            Y = datetime.getFullYear(),
            M = datetime.getMonth() + 1,
            D = datetime.getDate(),
            H = datetime.getHours(),
            m = datetime.getMinutes(),
            s = datetime.getSeconds()
        switch (type) {
            case 'YYYY-MM':
                datetime_format = `${Y}-${repair(M)}`
            break;
            case 'YYYY-MM-DD':
                datetime_format = `${Y}-${repair(M)}-${repair(D)}`
            break;
            case 'HH:mm':
                datetime_format = `${repair(H)}:${repair(m)}`
            break;
            case 'HH:mm:ss':
                datetime_format = `${repair(H)}:${repair(m)}:${repair(s)}`
            break;
            case 'YYYY-MM-DD HH:mm':
                datetime_format = `${Y}-${repair(M)}-${repair(D)} ${repair(H)}:${repair(m)}`
            break;
            case 'YYYY-MM-DD HH:mm:ss':
                datetime_format = `${Y}-${repair(M)}-${repair(D)} ${repair(H)}:${repair(m)}:${repair(s)}`
            break;
            case 'YYYY/MM':
                datetime_format = `${Y}/${repair(M)}`
            break;
            case 'YYYY/MM/DD':
                datetime_format = `${Y}/${repair(M)}/${repair(D)}`
            break;
            case 'YYYY/MM/DD HH:mm':
                datetime_format = `${Y}/${repair(M)}/${repair(D)} ${repair(H)}:${repair(m)}`
            break;
            case 'YYYY/MM/DD HH:mm:ss':
                datetime_format = `${Y}/${repair(M)}/${repair(D)} ${repair(H)}:${repair(m)}:${repair(s)}`
            break;
            default:
            break;
        }
    }
    return {
        format
    }
}

//   
moment().format('YYYY-MM-DD HH:mm:ss')
moment('2020-12-12 23:23:24').format('HH:mm:ss')
moment('2020/12/12 23:23:24').format('YYYY-MM')

 

좋은 웹페이지 즐겨찾기