Home  >  Article  >  Web Front-end  >  JavaScript implements an illegal implementation method to display when entering a name

JavaScript implements an illegal implementation method to display when entering a name

黄舟
黄舟Original
2017-05-25 09:24:302163browse

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=&#39;text&#39; class=&#39;normal&#39; name=&#39;name&#39; pattern=&#39;required&#39; alt=&#39;名称&#39;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(/[`~!@#$%^&*()_+<>?:"{},.\/;&#39;[\]]/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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn