js 输入框验证问题
2018-12-11 10:37 马尔代夫_珍 阅读(310) 评论(0) 编辑 收藏 举报
一开始input中可输入内容的要求都写到后台,实际上可以在前端js中加正则验证
//var LengNum=Request.Form["otherjudge"].Tostring().Length;
//var LengNum = OtherJudge.Length;
//if (LengNum > 7)
//{
// req.msg = "最多可输入7个汉字!";
// req.code = 1;
//}
js:
<input autocomplete="off" class="layui-input" onkeyup="value = value.replace(/[^\u4E00-\u9FA5]/g, '')" onbeforepaste=" clipboardData.setData('text', clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g, ''))" maxlength=7 name="otherjudge" id="otherjudge">