SoFunction
Updated on 2025-02-28

JavaScript input box content format verification code


<body>
Username: <input type="text" />
<div style="display:none; background:#999900;"></div> //The verification result is displayed, please note that display is hidden
<br />
Password: <input type="text" onfocus="bb()" /> // The onfocus event is triggered when the pwd input box gets focus to verify whether the content format of the name input box is correct.
<script>
var name = ("name");
function bb(){
= 'block'; //Show div
if((/^\w+/)) { //Use regular expressions to verify the entered username
= "dui";
}
else{
= "cuo";
}
}
</script>
</body>