matches验证电话号码,java使用正则表达式验证电话号码

matches验证电话号码,java使用正则表达式验证电话号码
matches验证电话号码,java使用正则表达式验证电话号码

验证电话号码

正则表达式常用发发总结

//判断输入内容是否为空 function IsNull(){ var str = document.getElementById('str').value.trim(); if(str.length==0){ alert('对不起,文本框不能为空或者为空格!'); //请将“文本框”改成你需要验证的属性名称! } } //判断日期类型是否为YYYY-MM-DD格式的类型 function IsDate(){ var str = document.getElementById('str').value.trim(); if(str.length!=0){ var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/; var r = str.match(reg); if(r==null) alert('对不起,您输入的日期格式不正确!'); //请将“日期”改成你需要验证的属性名称! } } //判断日期类型是否为YYYY-MM-DD hh:mm:ss格式的类型 function IsDateTime(){ var str = document.getElementById('str').value.trim();

if(str.length!=0){ var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}): (\d{1,2}):(\d{1,2})$/; var r = str.match(reg); if(r==null) alert('对不起,您输入的日期格式不正确!'); //请将“日期”改成你需要验证的属性名称! } } //判断日期类型是否为hh:mm:ss格式的类型 function IsTime() { var str = document.getElementById('str').value.trim(); if(str.length!=0){ reg=/^((20|21|22|23|[0-1]\d)\:[0-5][0-9])(\:[0-5][0-9])?$/ if(!reg.test(str)){ alert("对不起,您输入的日期格式不正确!"); //请将“日期”改成你需要验证的属性名称! } } } //判断输入的字符是否为英文字母

表单验证和正则表达式

正则表达式和表单验证 主要内容 ?什么是表单的验证 ?表单的操作 ?表单的验证 ?正则表达式的定义 ?正则表达式验证 (一)什么是表单的验证 表单的验证 在JavaScript之前,所有的验证都是发生在服务器上,增加了反应 时间 使用JavaScript验证,则在数据提交到服务器端之前进行一系列的 判断,比如数据不全或无效则取消提交,同时再提示重新输入. 表单的验证一般有两种形式 一个是在button按钮的onclick事件上完成,如果返回false则取消 提交 在提交按钮的onsubmit事件完成,如果返回false,表单不提交 常见的验证 文本框是否为空? 选择型的表单是否选择? 用户输入的邮件地址是否合法? 用户是否已输入合法的日期? (二)表单的操作 引用表单域 根据表单的名字获取表单的引用 var myForm = doucument.forms[“name”];

根据表单数组获取 var myForm = document.forms[0]; 表单中的属性 表单中的方法 表单中的事件 表单域中的通用属性 disabled属性 name属性:name的属性值是可以通过JavaScript改变 form属性:通过form属性可以获得一个表单域所在的表单 表单域中的通用方法 ?focus()方法 ?blur()方法

表单域中的通用事件 onfocus和onblur事件 onclick、onkeydown、onkeyup和onkeypress事件 onmouseover、onmouseout、onmousedown、和onmouseup事件 onchange事件 使用文本域 获取和设置文本域的值 使用select方法选中文本 使用按钮类表单域 简单按钮:最常用的方法捕获onclick事件,然后执行代码 复选按纽:通过checked属性获取,选中时是true,否则为false. 单选按钮:通过checked属性获取,选中时是true,否则为false. 使用下拉列表框 获取和设置下拉列表框的值 下拉列表框的值表示被选中的option标记的value属性 获取选项的个数 select对象有一个length属性,表示选项的个数 获取当前选项的索引 select对象中使用selectedIndex属性获取当前选中的option对象的索引 获取所有选项的集合 用options属性表示所有option组成的集合,option的value代表其值,text属性 代表其中间的文本,selected属性决定该option是否被选中 为select动态添加选项 在所有的option后面添加一个新的选项 Select.options[select.length] = new Option(“optiontext”,”value”); 从select中删除一个选项 ?Select.options[1] = null; 清空一个select 替换一个选项 Select.options[0] = new Option(“optiontext”,”value”);

正则表达式 Regular Expression 例子 sample VB版

VS SDK Regular Expression Language Service Example Deep Dive (VB) István Novák (DiveDeeper), Grepton Ltd. May, 2008 Introduction This example implements a small language service for demonstration purposes. This is called Regular Expression Language Service since it can tokenize text by RegEx patterns (lower case letters, capital letters, digits) and can use its own syntax coloring scheme for each token. However, the functionality of this sample is quite far away from a full language service it illustrates the basics. The source files belonging to this code have only about three hundred lines of essential code. When reading through this deep dive you are going to get familiar with the following concepts: How language services should be registered with Visual Studio? What kind of lifecycle management tasks a simple language service has? How to create a very simple language service? How to implement a scanner supporting syntax coloring? To understand concepts treated here it is assumed that you are familiar with the idea of VSPackages and you know how to build and register very simple (even non-functional) packages. To get more information about packages, please have a look at the Package Reference Sample (VisualBasic Reference.Package sample). Very basic knowledge about regular expressions is also expected. Regular Expression Language Service Open the Microsoft Visual Studio 2008 SDK Browser and select the Samples tab. In the top middle list you can search for the “VisualBasic Example.RegExLangServ” sample. Please, use the “Open this sample in Visual Studio” link at the top right panel of the browser app to prepare the sample. The application opens in Visual Studio 2008. Running the sample Rebuild the package and start it with the Experimental Hive! Without creating a new solution, add a new text file with the File|New|File... menu function. Use the File|Save As menu function to store the text file with the RegexFile.rgx name. To avoid attaching the .txt extension to the end of the file name, set the “Save as type” to “All files (*.*)” as illustrated in Figure 1:

正则表达式写的form表单验证

希望能帮助更多的人,可以加我qq交流504781715 formzzbds.html