惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
博客园 - 聂微东
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
罗磊的独立博客
H
Help Net Security
L
LangChain Blog
T
Threat Research - Cisco Blogs
量子位
S
Securelist
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
The Hacker News
The Hacker News
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Blog of Author Tim Ferriss
T
Threatpost
Security Latest
Security Latest
P
Palo Alto Networks Blog
Microsoft Security Blog
Microsoft Security Blog
NISL@THU
NISL@THU
F
Full Disclosure
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Heimdal Security Blog
J
Java Code Geeks
Recorded Future
Recorded Future
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
B
Blog RSS Feed
月光博客
月光博客
C
Cisco Blogs
V
Visual Studio Blog
D
DataBreaches.Net
H
Hacker News: Front Page
博客园 - 叶小钗
N
News and Events Feed by Topic
爱范儿
爱范儿
A
Arctic Wolf

博客园 - 阿木申

spring JPA 动态查询 iOS收到Push后播放声音和震动 [vb]sendkeys [vb]键盘精灵 - 阿木申 - 博客园 javascript 画带箭头的线段 关于input type='file'的内容的一种解决方法,模拟键盘 - 阿木申 - 博客园 防止IE缓存,就相当于IE选择每次打开就检查 - 阿木申 - 博客园 [dojo] 解决传中文的乱码问题 - 阿木申 - 博客园 [dojo] dojo.xhrGet和.net整合使用 [dojo]好用的页面对话框dijit.Dialog [dojo]日期选择:dijit.form.DateTextbox dojo0.9 dojo.data研究笔记 [dojo] dojo 0.9 的使用心得 [原创]jBPM 子流程的使用 [原创]jBPM动态生成任务实例,会签或者分派任务时特别有用 [dojo转]动态生成widget [原创]jBpm中泳道使用心得 [原创]jBPM中的Expression和script [原创]JBPM中的基本操作代码
[dojo]功能强大的文本框:dijit.form.ValidationTextbox - 阿木申 - 博客园
阿木申 · 2007-07-25 · via 博客园 - 阿木申

功能强大的文本框: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="/amushen2005@hotmail.com"

                     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(); 是否符合校验规则

关于校验的正则表达式法比较灵活,功能也非常强大,可以到微软或者sun的官方网站查看一些权威的资料。或者直接上网上搜索一些常用的正则表达式。

下面给出一些常用正则表达式:

1、   非负整数:”^d+$”

2、   正整数:”^[0-9]*[1-9][0-9]*$”

3、   非正整数:”^((-d+)|(0+))$”

4、   负整数:”^-[0-9]*[1-9][0-9]*$”

5、   整数:”^-?d+$”

6、   非负浮点数:”^d+(.d+)?$”

7、   正浮点数:”^((0-9)+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*))$”

8、   非正浮点数:”^((-d+.d+)?)|(0+(.0+)?))$”

9、   负浮点数:”^(-((正浮点数正则式)))$”

10、英文字符串:”^[A-Za-z]+$”

11、英文大写串:”^[A-Z]+$”

12、英文小写串:”^[a-z]+$”

13、英文字符数字串:”^[A-Za-z0-9]+$”

14、英数字加下划线串:”^w+$”

15、E-mail地址:”^[w-]+(.[w-]+)*@[w-]+(.[w-]+)+$”

16、URL”^[a-zA-Z]+://(w+(-w+)*)(.(w+(-w+)*))*(?s*)?$”

17、匹配中文字符的正则表达式: [\u4e00-\u9fa5]

18、匹配双字节字符(包括汉字在内)[^\x00-\xff]

19、匹配HTML标记的正则表达式:/<(.*)>.*<\/\1>|<(.*) \/>/

20、匹配国内电话号码:\d{3}-\d{8}|\d{4}-\d{7}

21、匹配中国邮政编码:[1-9]\d{5}(?!\d)

22、匹配身份证:\d{15}|\d{18}


原文地址:http://www.dojocn.cn/apage/amushen/archives/2007/20.html
转自:http://www.dojocn.cn/