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 validate form forms with JavaScrip regular expressions

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

Share

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

This article mainly explains "how to use JavaScrip regular expression to verify form form", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "how to use JavaScrip regular expression to verify form form" bar!

Document: between ta

Location:url

History: forward and backward

Function show () {/ / Pop up a prompt box window.alert ("hh");} / bind the show method to the button _ window.onload=function () {/ / navigate to the button var buttonElement=document.forms [0] .mybtn; / / dynamically bind the show method buttonElement.onclick=show / / show if you add (), the prompt box will pop up as soon as the web page is loaded} function validateForm () {var loginform=document.forms [1]; var username=trim (loginform.username.value); var password=trim (loginform.password.value); var email=trim (loginform.email.value); / / alert ("alternative length before:" + username.length); / / username=trim (username); / / alert ("length after substitution:" + username.length) / / determine that the user name is required: if (username.length==0) {alert ("user required");} else if (! / ^ [a-zA-Z0-9] + $/ .test (username)) {alert ("user name must be alphabet");} else if (password.length==0) {alert ("password required") } else if (! / ^ [0-9] {6} $/ .test (password)) {alert ("password must be 6 digits");} else if (email.length==0) {alert ("required mailbox");} else if (! / ^\ wang @\ w + (\.\ w+) + $/ .test (email)) {alert ("incorrect mailbox format") } return false;} / / Custom a parameter function trim (s) {/ / s.REPLACE (regular expression, substituted character) s=s.replace (/ ^\ s alternate character); return s; .myclass {position: absolute; left: 400px; top: 150px;}

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