处理blog的bug文档时候遇到的问题,如何屏蔽一些特殊字符,用到了一些正则表达式:

var regTest=/^[A-Za-z-0-9]+$/;

此时regTest中包含a-z的26个英文字母以及0-9的数字。贴代码如下:

HTML语言: Codee#8349
<BODY>
  <SCRIPT LANGUAGE="JavaScript">
  <!
    function Test(){
      var regTest=/^[A-Za-z-0-9]+$/;
     var TestOneValue=document.getElementById("TestOne").value;
      if(!regTest.exec(TestOneValue)){
        alert("有非法字符!");
      }else{
        alert("正常");
      }
    }
  </SCRIPT>
  <input type="text" id="TestOne" />
  <input type="button" value="测试" onclick="Test();"/>
</BODY>

另: /^[0-9]{1,20}$/ 判断是否是纯数字,表达式本身代表数字。

—-2008/12/19

Tags:

Related posts

Tags: .
Home

No Comments Now!

Be the first to comment on this entry.

Leave a comment

Name(required)
Mail (required),(will not be published)
Website(recommended)

Fields in bold are required. Email addresses are never published or distributed.

Some HTML code is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
URLs must be fully qualified (eg: http://hanghang.name),and all tags must be properly closed.

Line breaks and paragraphs are automatically converted.

Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.