How to use regular expressions to find letters and numbers in js
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