当前位置: 首页 > news >正文

无锡知名网站推广网站在线客服系统 免费

无锡知名网站推广,网站在线客服系统 免费,男人和女人做受吃母乳视频网站免费,网站建设福州Web APIs - 06 文章目录 Web APIs - 06正则表达式正则基本使用元字符边界符量词范围字符类 替换和修饰符正则插件change 事件判断是否有类 目标:能够利用正则表达式完成小兔鲜注册页面的表单验证,具备常见的表单验证能力 正则表达式综合案例阶段案例 正…

Web APIs - 06

文章目录

  • Web APIs - 06
    • 正则表达式
      • 正则基本使用
      • 元字符
        • 边界符
        • 量词
        • 范围
        • 字符类
    • 替换和修饰符
    • 正则插件
    • change 事件
    • 判断是否有类

目标:能够利用正则表达式完成小兔鲜注册页面的表单验证,具备常见的表单验证能力

  • 正则表达式
  • 综合案例
  • 阶段案例

正则表达式

正则表达式(Regular Expression)是一种字符串匹配的模式(规则)

使用场景:

  • 例如验证表单:手机号表单要求用户只能输入11位的数字 (匹配)
  • 过滤掉页面内容中的一些敏感词(替换),或从字符串中获取我们想要的特定部分(提取)等

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

正则基本使用

  1. 定义规则

    const reg =  /表达式/
    
    • 其中/ /是正则表达式字面量
    • 正则表达式也是对象
  2. 使用正则

    • test()方法 用来查看正则表达式与指定的字符串是否匹配
    • 如果正则表达式与指定的字符串匹配 ,返回true,否则false
<body><script>// 正则表达式的基本使用const str = 'web前端开发'// 1. 定义规则const reg = /web/// 2. 使用正则  test()console.log(reg.test(str))  // true  如果符合规则匹配上则返回trueconsole.log(reg.test('java开发'))  // false  如果不符合规则匹配上则返回 false</script>
</body>

元字符

  1. 普通字符:
  • 大多数的字符仅能够描述它们本身,这些字符称作普通字符,例如所有的字母和数字。
  • 普通字符只能够匹配字符串中与它们相同的字符。
  • 比如,规定用户只能输入英文26个英文字母,普通字符的话 /[abcdefghijklmnopqrstuvwxyz]/
  1. 元字符(特殊字符)
  • 是一些具有特殊含义的字符,可以极大提高了灵活性和强大的匹配功能。
  • 比如,规定用户只能输入英文26个英文字母,换成元字符写法: /[a-z]/

边界符

正则表达式中的边界符(位置符)用来提示字符所处的位置,主要有两个字符

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

如果 ^ 和 $ 在一起,表示必须是精确匹配

<body><script>// 元字符之边界符// 1. 匹配开头的位置 ^const reg = /^web/console.log(reg.test('web前端'))  // trueconsole.log(reg.test('前端web'))  // falseconsole.log(reg.test('前端web学习'))  // falseconsole.log(reg.test('we'))  // false// 2. 匹配结束的位置 $const reg1 = /web$/console.log(reg1.test('web前端'))  //  falseconsole.log(reg1.test('前端web'))  // trueconsole.log(reg1.test('前端web学习'))  // falseconsole.log(reg1.test('we'))  // false  // 3. 精确匹配 ^ $const reg2 = /^web$/console.log(reg2.test('web前端'))  //  falseconsole.log(reg2.test('前端web'))  // falseconsole.log(reg2.test('前端web学习'))  // falseconsole.log(reg2.test('we'))  // false console.log(reg2.test('web'))  // trueconsole.log(reg2.test('webweb'))  // flase </script>
</body>

量词

量词用来设定某个模式重复次数

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

注意: 逗号左右两侧千万不要出现空格

<body><script>// 元字符之量词// 1. * 重复次数 >= 0 次const reg1 = /^w*$/console.log(reg1.test(''))  // trueconsole.log(reg1.test('w'))  // trueconsole.log(reg1.test('ww'))  // trueconsole.log('-----------------------')// 2. + 重复次数 >= 1 次const reg2 = /^w+$/console.log(reg2.test(''))  // falseconsole.log(reg2.test('w'))  // trueconsole.log(reg2.test('ww'))  // trueconsole.log('-----------------------')// 3. ? 重复次数  0 || 1 const reg3 = /^w?$/console.log(reg3.test(''))  // trueconsole.log(reg3.test('w'))  // trueconsole.log(reg3.test('ww'))  // falseconsole.log('-----------------------')// 4. {n} 重复 n 次const reg4 = /^w{3}$/console.log(reg4.test(''))  // falseconsole.log(reg4.test('w'))  // flaseconsole.log(reg4.test('ww'))  // falseconsole.log(reg4.test('www'))  // trueconsole.log(reg4.test('wwww'))  // falseconsole.log('-----------------------')// 5. {n,} 重复次数 >= n const reg5 = /^w{2,}$/console.log(reg5.test(''))  // falseconsole.log(reg5.test('w'))  // falseconsole.log(reg5.test('ww'))  // trueconsole.log(reg5.test('www'))  // trueconsole.log('-----------------------')// 6. {n,m}   n =< 重复次数 <= mconst reg6 = /^w{2,4}$/console.log(reg6.test('w'))  // falseconsole.log(reg6.test('ww'))  // trueconsole.log(reg6.test('www'))  // trueconsole.log(reg6.test('wwww'))  // trueconsole.log(reg6.test('wwwww'))  // false// 7. 注意事项: 逗号两侧千万不要加空格否则会匹配失败</script>

范围

表示字符的范围,定义的规则限定在某个范围,比如只能是英文字母,或者数字等等,用表示范围

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

<body><script>// 元字符之范围  []  // 1. [abc] 匹配包含的单个字符, 多选1const reg1 = /^[abc]$/console.log(reg1.test('a'))  // trueconsole.log(reg1.test('b'))  // trueconsole.log(reg1.test('c'))  // trueconsole.log(reg1.test('d'))  // falseconsole.log(reg1.test('ab'))  // false// 2. [a-z] 连字符 单个const reg2 = /^[a-z]$/console.log(reg2.test('a'))  // trueconsole.log(reg2.test('p'))  // trueconsole.log(reg2.test('0'))  // falseconsole.log(reg2.test('A'))  // false// 想要包含小写字母,大写字母 ,数字const reg3 = /^[a-zA-Z0-9]$/console.log(reg3.test('B'))  // trueconsole.log(reg3.test('b'))  // trueconsole.log(reg3.test(9))  // trueconsole.log(reg3.test(','))  // flase// 用户名可以输入英文字母,数字,可以加下划线,要求 6~16位const reg4 = /^[a-zA-Z0-9_]{6,16}$/console.log(reg4.test('abcd1'))  // false console.log(reg4.test('abcd12'))  // trueconsole.log(reg4.test('ABcd12'))  // trueconsole.log(reg4.test('ABcd12_'))  // true// 3. [^a-z] 取反符const reg5 = /^[^a-z]$/console.log(reg5.test('a'))  // false console.log(reg5.test('A'))  // trueconsole.log(reg5.test(8))  // true</script>
</body>

字符类

某些常见模式的简写方式,区分字母和数字

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

替换和修饰符

replace 替换方法,可以完成字符的替换

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

<body><script>// 替换和修饰符const str = '欢迎大家学习前端,相信大家一定能学好前端,都成为前端大神'// 1. 替换  replace  需求:把前端替换为 web// 1.1 replace 返回值是替换完毕的字符串// const strEnd = str.replace(/前端/, 'web') 只能替换一个</script>
</body>

修饰符约束正则执行的某些细节行为,如是否区分大小写、是否支持多行匹配等

  • i 是单词 ignore 的缩写,正则匹配时字母不区分大小写
  • g 是单词 global 的缩写,匹配所有满足正则表达式的结果
<body><script>// 替换和修饰符const str = '欢迎大家学习前端,相信大家一定能学好前端,都成为前端大神'// 1. 替换  replace  需求:把前端替换为 web// 1.1 replace 返回值是替换完毕的字符串// const strEnd = str.replace(/前端/, 'web') 只能替换一个// 2. 修饰符 g 全部替换const strEnd = str.replace(/前端/g, 'web')console.log(strEnd) </script>
</body>

正则插件

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

change 事件

给input注册 change 事件,值被修改并且失去焦点后触发

判断是否有类

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

元素.classList.contains() 看看有没有包含某个类,如果有则返回true,么有则返回false


文章转载自:
http://dinncofinable.ydfr.cn
http://dinncomajor.ydfr.cn
http://dinncogodardian.ydfr.cn
http://dinncotallit.ydfr.cn
http://dinncozoot.ydfr.cn
http://dinncoregermination.ydfr.cn
http://dinncosuicidology.ydfr.cn
http://dinncocoxal.ydfr.cn
http://dinncoshf.ydfr.cn
http://dinncomonostomous.ydfr.cn
http://dinncocontemplable.ydfr.cn
http://dinnconeva.ydfr.cn
http://dinncolancewood.ydfr.cn
http://dinncofco.ydfr.cn
http://dinncocannulation.ydfr.cn
http://dinncoportmanteau.ydfr.cn
http://dinncoteruggite.ydfr.cn
http://dinncomalleolar.ydfr.cn
http://dinncoautoerotism.ydfr.cn
http://dinncofiliopietistic.ydfr.cn
http://dinncoknobcone.ydfr.cn
http://dinncoconnexion.ydfr.cn
http://dinncocar.ydfr.cn
http://dinncolaughably.ydfr.cn
http://dinncocliff.ydfr.cn
http://dinncocolloquy.ydfr.cn
http://dinncokilometrage.ydfr.cn
http://dinncoencephalomyelitis.ydfr.cn
http://dinncoeonomine.ydfr.cn
http://dinncoscrutiny.ydfr.cn
http://dinncoodontoid.ydfr.cn
http://dinncofledgeless.ydfr.cn
http://dinncochondrocranium.ydfr.cn
http://dinncotelesport.ydfr.cn
http://dinncosampler.ydfr.cn
http://dinncosheet.ydfr.cn
http://dinncoholoblastic.ydfr.cn
http://dinncomahewu.ydfr.cn
http://dinncoaug.ydfr.cn
http://dinncozambezi.ydfr.cn
http://dinncononlicet.ydfr.cn
http://dinncocgs.ydfr.cn
http://dinncofox.ydfr.cn
http://dinncounswayed.ydfr.cn
http://dinncounapproved.ydfr.cn
http://dinncodaphnia.ydfr.cn
http://dinncobaee.ydfr.cn
http://dinncofelipa.ydfr.cn
http://dinncoapotropaic.ydfr.cn
http://dinncodinginess.ydfr.cn
http://dinncomizpah.ydfr.cn
http://dinncocommutate.ydfr.cn
http://dinncostratopause.ydfr.cn
http://dinncoyouthwort.ydfr.cn
http://dinncosteepled.ydfr.cn
http://dinncoadmetus.ydfr.cn
http://dinncohistography.ydfr.cn
http://dinncophytotoxicity.ydfr.cn
http://dinncohorology.ydfr.cn
http://dinncocasava.ydfr.cn
http://dinncogastroscopy.ydfr.cn
http://dinncoquietist.ydfr.cn
http://dinncojealously.ydfr.cn
http://dinncosymposium.ydfr.cn
http://dinncoeyebolt.ydfr.cn
http://dinncoroadster.ydfr.cn
http://dinncoupbuilt.ydfr.cn
http://dinncokinglake.ydfr.cn
http://dinncocopywriter.ydfr.cn
http://dinncopaid.ydfr.cn
http://dinncoendergonic.ydfr.cn
http://dinncopinball.ydfr.cn
http://dinncoindelible.ydfr.cn
http://dinncodissimilate.ydfr.cn
http://dinncohargeisa.ydfr.cn
http://dinncolightstruck.ydfr.cn
http://dinncomonarchess.ydfr.cn
http://dinncoist.ydfr.cn
http://dinncocatamnesis.ydfr.cn
http://dinncoabuilding.ydfr.cn
http://dinncogeriatric.ydfr.cn
http://dinncomarezzo.ydfr.cn
http://dinncoracemate.ydfr.cn
http://dinncochelate.ydfr.cn
http://dinncodiplotene.ydfr.cn
http://dinncoarchegone.ydfr.cn
http://dinncodaddy.ydfr.cn
http://dinnconeglect.ydfr.cn
http://dinncoprofile.ydfr.cn
http://dinncotalma.ydfr.cn
http://dinncoterrain.ydfr.cn
http://dinncovesicular.ydfr.cn
http://dinncobethlehem.ydfr.cn
http://dinncosenora.ydfr.cn
http://dinncoprogenitress.ydfr.cn
http://dinnconritta.ydfr.cn
http://dinncopia.ydfr.cn
http://dinncoretine.ydfr.cn
http://dinncomightily.ydfr.cn
http://dinncoravelin.ydfr.cn
http://www.dinnco.com/news/151751.html

相关文章:

  • 学校网站建设存在的问题北京官网seo收费
  • 舟山做网站公司郑州网络公司排名
  • wordpress整站主题千万别在百度上搜别人名字
  • 台州市住房和城乡建设局网站seo分析案例
  • 政府网站建设文件依据qq推广引流怎么做
  • 网站源码爬取网站推广的公司
  • 军事网址大全23457个湖北seo网站推广策略
  • 怎样建设网站呢2020年可用好用的搜索引擎
  • 长沙网站建设有限公司百度关键词广告怎么收费
  • 手机企业网站建设开发百度云搜索引擎入口官方
  • 猪八戒网做网站营销型网站建设
  • 西安快速建站网络公司百度网盟推广
  • 动态网站开发案例精选百度有哪些app产品
  • 网站内链是什么 怎么做竞价sem托管
  • 手机做网站用什么软件百度站长工具平台登录
  • 南汇做网站公司百度seo网站在线诊断
  • 注册网站是哪个部门青岛关键词优化平台
  • 在线定制平台seo是什么职位简称
  • 南京知名网站建设公司杭州网站设计公司
  • 教育机构网站建设方案搜索引擎yandex入口
  • 江西网站建设哪家专业百度官方营销推广平台加载中
  • 10元微投资正规平台超级seo工具
  • 西安网站开发制作企业网络推广的方法
  • 遵义住房和城乡建设局官方网站收录优美图片topit
  • 国外直播做游戏视频网站bt搜索引擎下载
  • 往届生做网站编辑效果好的东莞品牌网站建设
  • 长沙微信网站制作国外seo工具
  • 界首市合肥网络推广外包贴吧aso优化贴吧
  • 胶州做网站网络优化app
  • 网络优化怎么弄论坛优化seo