沉睡个人博客
沉睡个人博客
博客
工具箱
留言板
沉睡个人博客
博客
工具箱
首页
前端
【jquery】js正则表达式
【jquery】js正则表达式
1,811人已阅读
时间:2022-03-19 00:00:00
<p><strong style="white-space:"><span style="font-size:">验证手机号的正则</span></strong></p><pre style="word-wrap:">/^1[3456789]d{9}$/</pre><p><br/></p><p style="white-space:"><strong>验证6-20英文数字组合的正则</strong></p><pre>^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$</pre><p><br/></p><p><strong>常用正则表达式—邮箱(Email)</strong></p><p></p><p style="font-size: 21px; line-height: 1.5; margin: 10px 0px; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; white-space: normal; background-color: rgb(255, 255, 255);">实例1、只允许英文字母、数字、下划线、英文句号、以及中划线组成</p><p style="margin: 10px auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">举例:zhangsan-001@gmail.com <br/>分析邮件名称部分:</p><ul style="list-style-type: none;" class=" list-paddingleft-2"><li><p>26个大小写英文字母表示为<code>a-zA-Z</code></p></li><li><p>数字表示为<code>0-9</code></p></li><li><p>下划线表示为<code>_</code></p></li><li><p>中划线表示为<code>-</code></p></li><li><p>由于名称是由若干个字母、数字、下划线和中划线组成,所以需要用到<code>+</code>表示多次出现</p></li></ul><p style="margin: 10px auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"> 根据以上条件得出邮件名称表达式:<code>[a-zA-Z0-9_-]+</code> <br/><br/><br/>分析域名部分:</p><p style="margin: 10px auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"> 一般域名的规律为“[N级域名][三级域名.]二级域名.顶级域名”,比如“qq.com”、“www.qq.com”、“mp.weixin.qq.com”、“12-34.com.cn”,分析可得域名类似“<code>**</code> <code>.**</code> <code>.**</code> <code>.**</code>”组成。</p><ul style="list-style-type: none;" class=" list-paddingleft-2"><li><p>“**”部分可以表示为<code>[a-zA-Z0-9_-]+</code></p></li><li><p>“.**”部分可以表示为<code>\.[a-zA-Z0-9_-]+</code></p></li><li><p>多个“.**”可以表示为<code>(\.[a-zA-Z0-9_-]+)+</code></p></li></ul><p style="margin: 10px auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"> 综上所述,域名部分可以表示为<code>[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+</code></p><p style="margin: 10px auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">最终表达式: <br/> 由于邮箱的基本格式为“名称@域名”,需要使用“^”匹配邮箱的开始部分,用“$”匹配邮箱结束部分以保证邮箱前后不能有其他字符,所以最终邮箱的正则表达式为: <br/> <code>^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$</code></p><p style="margin: 10px auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"> </p><p style="font-size: 21px; line-height: 1.5; margin: 10px 0px; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; white-space: normal; background-color: rgb(255, 255, 255);"><a></a>实例2、名称允许汉字、字母、数字,域名只允许英文域名</p><p style="margin: 10px auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">举例:杨元庆001Abc@lenovo.com.cn</p><p style="margin: 10px auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">分析邮件名称部分:</p><ul style="list-style-type: none;" class=" list-paddingleft-2"><li><p>汉字在正则表示为<code>[\u4e00-\u9fa5]</code></p></li><li><p>字母和数字表示为<code>A-Za-z0-9</code> <br/> 通过分析得出邮件名称部分表达式为<code>[A-Za-z0-9\u4e00-\u9fa5]+</code></p></li></ul><p style="margin: 10px auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">分析邮件域名部分</p><p style="margin: 10px auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"> 邮件部分可以参考<code>实例1</code>中的<code>分析域名部分</code>。 <br/> 得出域名部分的表达式为<code>[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+</code>。</p><p style="margin: 10px auto; color: rgb(35, 35, 35); font-family: Verdana, Arial, helvetica, sans-seriff; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">最终表达式: <br/> 我们用@符号将邮箱的名称和域名拼接起来,因此完整的邮箱表达式为 <br/> <code>^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$</code></p><p><br/></p>
上一篇:【CSS】CSS鼠标效果
下一篇:【jquery】js两个数组拼接