正则表达式的验证
发布时间:2020-12-14 01:15:33 所属栏目:百科 来源:网络整理
导读:!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"html xmlns="http://www.w3.org/1999/xhtml"head meta http-equiv="Content-Type" content="text/html; charset=utf-8" / meta h
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="zh-CN" /> <title> New Document </title> <script src="__PUBLIC__/Js/jquery-1.8.3.min.js"></script> <script> $(document).ready(function(){ $("#regex").css("width",300); var $tel = new RegExp($("#regex").val()); $("#btn").click(function(){ if($tel.test($("#regexValidate").val())){ alert("nice!"); }else{ alert("Oh No"); } }); }); </script> </head> <body> <!-- 默认:只含有汉字、数字、字母、下划线不能以下划线开头和结尾的正则表达式 --> <span>正则表达式:</span> <input type="text" id="regex" value="^(?!_)(?!.*?_$)[a-zA-Z0-9_u4e00-u9fa5]+$" /> <br></br> <input type="text" id="regexValidate" value=""></input> <input type="button" id="btn" value="验证"/> </body> </html>正则表达式的即时验证哦 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |