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

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

黄舟
Release: 2017-05-25 09:24:30
Original
2198 people have browsed it

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>
Copy after login

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 ("名称不能含有非法字符!");
   }   
  }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template