Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

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

Shulou Source: shulou.com Published: 2022-06-02 06:14:05 10月03日 Update

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

Tags: Letters numbers rules expressions methods articles content passwords scripts length special not so world code hello most more knowledge symbols industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia macOS MySQL Redmi Linux