layui 表單驗證案例文字框,手機,郵箱,textarea等格式的驗證
阿新 • • 發佈:2019-01-08
文字框,手機,郵箱,textarea等格式的驗證
<script src="layui/layui.js"></script>
<script src="layui/lay/dest/layui.all.js"></script><link rel="stylesheet" href="layui/css/layui.css">
HTML程式碼:
- <formclass="layui-form"action="">
-
<divclass="layui-form-item"
- <labelclass="layui-form-label">反饋主題</label>
- <divclass="layui-input-block">
- <inputname="title"class="layui-input"type="text"placeholder="請輸入標題"autocomplete="off"lay-verify="title">
-
</
- </div>
- <divclass="layui-form-item">
- <labelclass="layui-form-label">姓名</label>
- <divclass="layui-input-block">
-
<inputname="fname"
- </div>
- </div>
- <divclass="layui-form-item">
- <labelclass="layui-form-label">手機</label>
- <divclass="layui-input-block">
- <inputname="phone"class="layui-input"type="tel"autocomplete="off"placeholder="請輸入手機"lay-verify="phone">
- </div>
- </div>
- <divclass="layui-form-item">
- <labelclass="layui-form-label">郵箱</label>
- <divclass="layui-input-block">
- <inputname="email"class="layui-input"type="text"autocomplete="off"placeholder="請輸入郵箱"lay-verify="email">
- </div>
- </div>
- <divclass="layui-form-item">
- <labelclass="layui-form-label">單選框</label>
- <divclass="layui-input-block">
- <inputname="sex"title="男"type="radio"checked=""value="男">
- <inputname="sex"title="女"type="radio"value="女">
- <inputname="sex"title="保密"type="radio"value="密">
- </div>
- </div>
- <!--<divclass="layui-form-item layui-form-text">
- <labelclass="layui-form-label">普通文字域</label>
- <divclass="layui-input-block">
- <textareaclass="layui-textarea"placeholder="請輸入內容">請輸入內容</textarea>
- </div>
- </div>-->
- <divclass="layui-form-item layui-form-text">
- <labelclass="layui-form-label">內容</label>
- <divclass="layui-input-block">
- <textareaclass="layui-textarea layui-hide"name="contact"id="LAY_demo_editor"lay-verify="contact"></textarea>
- </div>
- </div>
- <divclass="layui-form-item">
- <divclass="layui-input-block">
- <buttonclass="layui-btn"lay-filter="demo2"lay-submit="">跳轉式提交</button>
- <buttonclass="layui-btn"lay-filter="demo1"lay-submit="">立即提交</button>
- <buttonclass="layui-btn layui-btn-primary"type="reset">重置</button>
- </div>
- </div>
- </form>
js驗證程式碼
- <script>
- layui.use(['form', 'layedit', 'laydate'], function(){
- var form = layui.form()
- ,layer = layui.layer
- ,layedit = layui.layedit
- ,laydate