This article mainly introduces the JavaScript method to set the name input to be illegal. Friends in need can refer to the
html code:
<tr> <th>输入名称:</th> <td><input type='text' class='normal' name='name' pattern='required' alt='名称'id="checkText" onblur="checkName()" /><label>* 特价活动名称</label></td> </tr>
Set id and onblur in the form Event onblur: will occur when the object loses focus.
javascript code:
function checkName() { //获取表单ID var cashName = document.getElementById("checkText").value; //正则匹配 var result=cashName.match(/[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im); if(result!=null) { document.getElementById("checkText").value=""; alert ("名称不能含有非法字符!"); } }
The above is the detailed content of JavaScript implements an illegal implementation method to display when entering a name. For more information, please follow other related articles on the PHP Chinese website!