dojo之ValidationTextbox

功能强大的文本框:dijit.form.ValidationTextbox
这个文本输入框的功能比较强大,关键是它能够提供一些常用的验证和大小写转换。下面介绍一个例子和一些常用的属性:
<html>

 

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>validationTextbox</title>
<style type="text/css">
       @import "../js/dojo/resources/dojo.css";
       @import "../js/dijit/themes/tundra/tundra.css";
       .dijitInputFieldFocused{
              border:solid 2px #FFDF00;                 
       }
</style>          
 
<script type="text/javascript"
       djConfig="parseOnLoad: true, isDebug: true"
       src="../js/dojo/dojo.js"></script>
       <script>
              dojo.require("dijit.form.ValidationTextbox");
              dojo.require("dijit.form.NumberTextbox");
             
       </script>
</head>
 
<body class="tundra">
<form name="form1">
       <input type="text" id="vt" dojoType="dijit.form.ValidationTextbox"          
              promptMessage="请输入信息"
              invalidMessage="输入的信息有误"
              required="true"
              trim="true"
              propercase="true"
       ><br />
 
一些属性:<br />
required="true"              //必须填写<br />
trim="true"                   //将前后的空格自动删除<br />
propercase="true"   //单词首字母大写<br />
uppercase="true"    //大写字母形式<br />
lowercase="true"    //小写字母形式<br />
<hr />
验证文本组件可以支持正则表达式验证,比如:<br />
不包含空格验证:<input id="vt1" type="text" name="phone" value="someTestString"
                     dojoType="dijit.form.ValidationTextbox"
                     regExp="[/w]+"
                     required="true"
                     trim="true"
                     invalidMessage="输入中不允许包含空格"><br />
 
email地址验证:<input id="vt2" type="text" name="phone" value="/[email protected]"
                     dojoType="dijit.form.ValidationTextbox"
                     regExp="(/w+@/w+/./w+)(/.{0,1}/w*)(/.{0,1}/w*)"
                     required="true"
                     trim="true"
                     invalidMessage="输入合法的email地址"><br />
只允许输入数字:                    
<input id="vt1" type="text" name="phone" value="/123.34"
                     dojoType="dijit.form.NumberTextbox"               
                     required="true"
                     trim="true"
                     invalidMessage="只允许输入数字"><br />
                    
</form>
</body>
</html>
 
ValidationTextbox 的一些常用方法:
setValue(); //不要使用.value或者.innerHTML来设置值,你可能设置不成功或者失去校验
getValue();
validate(); 手工校验
isEmpty(); 是否为空
isValid(); 是否符合校验规则

你可能感兴趣的:(dojo之ValidationTextbox)