企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 表单验证 ```html <div class="container" id="dv"> <label for="qq">Q Q</label><input type="text" id="qq"><span></span><br /> <label>手机</label><input type="text" id="phone"><span></span><br /> <label>邮箱</label><input type="text" id="e-mail"><span></span><br /> <label>座机</label><input type="text" id="telephone"><span></span><br /> <label>姓名</label><input type="text" id="fullName"><span></span><br /> </div> <script src="public.js"></script> ``` ```javascript function getInput(input, reg) { // 输入框失焦事件 input.onblur = function () { if (reg.test(this.value)) { this.nextElementSibling.innerText = "正确了";//当前的下一个兄弟元素 this.nextElementSibling.style.color = "green"; } else { this.nextElementSibling.innerText = "错了"; this.nextElementSibling.style.color = "red"; } } } //正则要是严格模式的 getInput(my$("qq"), /^\d{5,11}$/); getInput(my$("phone"), /^\d{11}$/); getInput(my$("e-mail"), /^[0-9a-zA-Z_.-]+[@][0-9a-zA-Z_.-]+([.][a-zA-Z]+){1,2}$/); getInput(my$("telephone"),/^\d{3,4}[-]\d{8}$/); getInput(my$("fullName"),/^[\u4e00-\u9fa5]{2,6}$/); ```