vue去除特殊字符Mixin

export const trim = {
    methods: {
        trim(value) {
            /**去除首尾空白 */
            return value.replace(/(^\s*)|(\s*$)/g, "");
        },

    }
}
export const validateSpecialCharacter = {
    methods: {
       /**验证特殊字符和空格 */
       inputformat (event,value) { 
            if (this.composing) {
                return
            }
            let inputValue = event.target.value
            event.target.value = event.target.value.replace(/[^\a-\z\A-\Z0-9_\u4E00-\u9FA5]/g, "")
            let filterValue = inputValue.replace(/[^\a-\z\A-\Z0-9_\u4E00-\u9FA5]/g, "")
            util.setDeepValue(value,filterValue)(this);
            event.target.dispatchEvent(new Event('input'))
        },
        compositionstart (data) {
            this.composing = true
        },
        compositionend ($event) {
            this.composing = false
        }
    }
}


猜你喜欢

转载自blog.csdn.net/weixin_37221852/article/details/81297546