1. 只能输入数字:
<input id="num" type="number" value="0" οnkeyup="value=value.replace(/[^\d]/g,'')">2. 只能输入手机号:
if (dom.type === "number") { v_2 = v.replace(/[^\d]/g,'') if (v_2.length > 11) { v_2 = v_2.substring(0, 11) } }function upperCase(){
var phone = $('.DI-input-iphone').val(); if(!(/^1[34578]\d{9}$/.test(phone)) && phone!=''){ return false; } else{ return true } } 3. 限制输入内容长度为49位,多余的删除: if (v_2.length > 49) {v_2 = v_2.substring(0, 49) }