How to use javascript regular expressions
This article introduces the knowledge of "how to use javascript regular expressions". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Form validation
Simple layout:
Q Q
Mobile phone
Mailbox
Landline
Name
Js Code:
CheckInput (my$ ("qq"), / ^\ d {5pm 11} $/); / / qq
CheckInput (my$ ("phone"), / ^\ d {11} $/); / / Mobile phone
CheckInput (my$ ("e-mail"), / ^ [0-9amurzAmurzZcolors. -] + [@] [0-9aMuzAmurZenzenz.-] + ([.] [a-zA-Z] +) {1jin2} $/); / / mailbox
CheckInput (my$ ("telephone"), / ^\ d {3jue 4} [-]\ d {7pm 8} $/); / / landline number
CheckInput (my$ ("fullName"), / ^ [\ u4e00 -\ u9fa5] {2pr 6} $/); / / Chinese name / / verify whether the current text box matches and displays the result through regular expression
Function checkInput (input,reg) {
/ / text box registers events that lose focus
Input.onblur=function () {
If (reg.test (this.value)) {
This.nextElementSibling.innerText= "got it right"
This.nextElementSibling.style.color= "green"
} else {
This.nextElementSibling.innerText= "Let you show off, wrong?"
This.nextElementSibling.style.color= "red"
}
}
}
That's all for "how to use javascript regular expressions". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!