Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use regular expressions to find letters and numbers in js

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to use regular expressions to find letters and numbers in js, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

The specific code is as follows:

_ window.onload=function () {localStorage.fiveData= "Hello to the world"; / / alert (localStorage.fiveData); / / var reg=/\ dAccordash / match any length digit var reg=/ [a Lizi Z] / g reg / match any letter var str= "aajdaf1232jadlfjakdjfalkjlakfj2131l34kalfsjaafaqejqe231wk"; var t=str.match (reg); for (var c in t) {console.log (t [c]);}}

Let's take a look at how JS uses regular expressions to verify that passwords contain numbers and letters.

Must contain at least one digit and one letter, scripted as follows:

The function CheckPassWord (password) {/ / password must contain numbers and the letters var str = password; if (str = = null | | str.length < 8) {return false;} var reg = new RegExp (/ ^ (?! [^ a-zA-Z] + $) (?!\ zA-Z $) /); if (reg.test (str)) return true;}

Must contain numbers plus letters and cannot contain special symbols, etc. The script method is as follows:

Function CheckPassWord (password) {/ / must be alphanumeric and have a length of not less than 8 digits var str = password; if (str = = null | | str.length

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report