一个可以用来检测输入字符的widget

来源:互联网 发布:android程序员ios 编辑:程序博客网 时间:2024/05/18 14:28

通过ValidationTextBox我们可以轻松去检测用户输入的字符是否满足规定,通过validationTextBox的一个属性:regExp,给regExp来赋于一个正则表达式来规定输入的字符应该满足哪种要求。

常用的正则表达式: 点击打开链接

当输入有误时会改变textbox的外观,比较醒目

  

一个控制输入为数字没有空格的textbox程序:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html dir="ltr">        <head>        <style type="text/css">            body, html { font-family:helvetica,arial,sans-serif; font-size:90%; }        </style>        <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/dojo.xd.js"        djConfig="parseOnLoad: true">        </script>        <script type="text/javascript">            dojo.require("dijit.form.ValidationTextBox");        </script>        <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css"        />    </head>        <body class=" claro ">        <input type="text" name="phone" id="phone" value="someTestString" dojoType="dijit.form.ValidationTextBox"        regExp="[\w]+" required="true" invalidMessage="Invalid Non-Space Text.">        <label for="phone">            Phone number, no spaces        </label>        <!-- NOTE: the following script tag is not intended for usage in real        world!! it is part of the CodeGlass and you should just remove it when        you use the code -->        <script type="text/javascript">            dojo.addOnLoad(function() {                if (document.pub) {                    document.pub();                }            });        </script>    </body></html>


原创粉丝点击