控制input输入数字非中文

2020-01-03  本文已影响0人  sssgoEasy

事件:1. onKeypress 2. onkeyup

代码:

        <input
            class="mobile-input"
            v-bind="$attrs"
            ref="input"
            :value="currentValue"
            @input="handleInput"
            @change="handleChange"
            v-focus="focusState"
            @click.stop="handleClick"
            maxlength="11"
            type="tel"
            onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"
            onkeyup="value=value.replace(/[\u4e00-\u9fa5]/ig,'')"
            :placeholder="placeholder"
        />

方法:

  1. 数字:onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"

  2. 非中文:onkeyup="value=value.replace(/[\u4e00-\u9fa5]/ig,'')"

上一篇 下一篇

猜你喜欢

热点阅读