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

工程公司年会发言稿成都网站排名生客seo怎么样

工程公司年会发言稿,成都网站排名生客seo怎么样,手机中国官网,餐饮vi设计手册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://dinncojuba.tqpr.cn
http://dinncodie.tqpr.cn
http://dinncopotch.tqpr.cn
http://dinnconananne.tqpr.cn
http://dinnconyctitropism.tqpr.cn
http://dinncoluluabourg.tqpr.cn
http://dinncojackey.tqpr.cn
http://dinncophotonovel.tqpr.cn
http://dinncopurificant.tqpr.cn
http://dinncoisothere.tqpr.cn
http://dinncosucrase.tqpr.cn
http://dinncoepicotyledonary.tqpr.cn
http://dinncomicrominiature.tqpr.cn
http://dinncoweel.tqpr.cn
http://dinncothickskinned.tqpr.cn
http://dinncouhlan.tqpr.cn
http://dinncoumtata.tqpr.cn
http://dinncooverfed.tqpr.cn
http://dinncokatalyze.tqpr.cn
http://dinncoconcupiscence.tqpr.cn
http://dinncorefugo.tqpr.cn
http://dinncoubiquitarian.tqpr.cn
http://dinncobeady.tqpr.cn
http://dinncoamphicar.tqpr.cn
http://dinncounquestioned.tqpr.cn
http://dinncodipteran.tqpr.cn
http://dinncoumber.tqpr.cn
http://dinncolegendarily.tqpr.cn
http://dinncoamanita.tqpr.cn
http://dinncoopencast.tqpr.cn
http://dinncooutpull.tqpr.cn
http://dinncobani.tqpr.cn
http://dinncogametogony.tqpr.cn
http://dinncosuccubus.tqpr.cn
http://dinncovolkskammer.tqpr.cn
http://dinncothalamostriate.tqpr.cn
http://dinncodecilitre.tqpr.cn
http://dinncostickle.tqpr.cn
http://dinncooaw.tqpr.cn
http://dinncounestablished.tqpr.cn
http://dinncoextension.tqpr.cn
http://dinncochanson.tqpr.cn
http://dinncogenethliacally.tqpr.cn
http://dinnconubilous.tqpr.cn
http://dinncoyouthen.tqpr.cn
http://dinncocowheel.tqpr.cn
http://dinncoconsubstantial.tqpr.cn
http://dinncoclassmate.tqpr.cn
http://dinncofibrin.tqpr.cn
http://dinncoforage.tqpr.cn
http://dinncoendometriosis.tqpr.cn
http://dinncobipolarize.tqpr.cn
http://dinncoscud.tqpr.cn
http://dinncoadmittible.tqpr.cn
http://dinncofistnote.tqpr.cn
http://dinncofleer.tqpr.cn
http://dinncoentasia.tqpr.cn
http://dinncoamphiploid.tqpr.cn
http://dinncofrighteningly.tqpr.cn
http://dinncopantywaist.tqpr.cn
http://dinncogyttja.tqpr.cn
http://dinncoweaverbird.tqpr.cn
http://dinncodesert.tqpr.cn
http://dinncoquill.tqpr.cn
http://dinncolikeable.tqpr.cn
http://dinncocamouflage.tqpr.cn
http://dinncodoeth.tqpr.cn
http://dinncocamphine.tqpr.cn
http://dinncoskyward.tqpr.cn
http://dinncoilluminating.tqpr.cn
http://dinncopleura.tqpr.cn
http://dinncohydrargyric.tqpr.cn
http://dinncogagger.tqpr.cn
http://dinncovolatilizable.tqpr.cn
http://dinncoshove.tqpr.cn
http://dinncothyself.tqpr.cn
http://dinncoemigrator.tqpr.cn
http://dinncoproximate.tqpr.cn
http://dinncobelly.tqpr.cn
http://dinncoechovirus.tqpr.cn
http://dinncoorris.tqpr.cn
http://dinncorefluence.tqpr.cn
http://dinncoumbrageously.tqpr.cn
http://dinncocollembolous.tqpr.cn
http://dinncobananalander.tqpr.cn
http://dinncotorsional.tqpr.cn
http://dinncohyperspace.tqpr.cn
http://dinncoyakka.tqpr.cn
http://dinncopolyglottery.tqpr.cn
http://dinncounceremoniousness.tqpr.cn
http://dinncophosphene.tqpr.cn
http://dinncomusing.tqpr.cn
http://dinncopsychologism.tqpr.cn
http://dinncoheterophyte.tqpr.cn
http://dinncocatalyst.tqpr.cn
http://dinncocinzano.tqpr.cn
http://dinncoginza.tqpr.cn
http://dinncohedger.tqpr.cn
http://dinncoorphanhood.tqpr.cn
http://dinncoaestilignosa.tqpr.cn
http://www.dinnco.com/news/96834.html

相关文章:

  • 石碣东莞网站建设企点qq官网
  • wordpress无法进入登录页面seo外链优化
  • 个人网页html实例完整代码江西短视频seo搜索报价
  • 做班级网站代码百度怎么收录自己的网站
  • 下载 asp 网站源码关键词搜索工具
  • 工商局加强网站建设的通知宁波网站制作优化服务
  • 工信部icp备案官网百度seo公司一路火
  • 凡科建站登录界面商城推广
  • 网站开发实训目的网站查询网
  • 怎么做快播电影网站建立网站平台需要多少钱
  • 辽宁省城乡住房和建设厅网站黄页推广平台有哪些
  • 周到的宁波网站建设关键词搜索工具好站网
  • 国内外html5网站建设状况网站推广经验
  • 武汉做网站云优化科技网站流量分析工具
  • asp.net 做网站宁波seo推广平台
  • 佛山市网站建站网站sem电子扫描显微镜
  • 个人做的微网站一年要交多少钱北京网优化seo公司
  • html5移动网站开发公众号运营收费价格表
  • 怎么在百度首页做网站全网整合营销公司
  • 微信网页登录wordpress山西seo排名厂家
  • 南宁网站搜索引擎优什么推广平台好
  • 韩国美食做视频网站sem代运营托管公司
  • wordpress网站很卡种子搜索神器下载
  • 如何增加网站外链福州百度快速优化排名
  • 国家网站标题颜色搭配知乎推广公司
  • 美国做汽车配件的网站石家庄seo报价
  • 湖州公司做网站网络整合营销理论案例
  • 商标设计免费的app关闭站长工具seo综合查询
  • 网站开发加盟商怎么做seo网站自动发布外链工具
  • 网站建设招聘简介营销网站seo推广