1. 程式人生 > >layui 表單驗證案例文字框,手機,郵箱,textarea等格式的驗證

layui 表單驗證案例文字框,手機,郵箱,textarea等格式的驗證

文字框,手機,郵箱,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程式碼:

  1. <formclass="layui-form"action="">
  2.                           <divclass="layui-form-item"
    >
  3.                             <labelclass="layui-form-label">反饋主題</label>
  4.                             <divclass="layui-input-block">
  5.                               <inputname="title"class="layui-input"type="text"placeholder="請輸入標題"autocomplete="off"lay-verify="title">
  6.                             </
    div>
  7.                           </div>
  8.                           <divclass="layui-form-item">
  9.                             <labelclass="layui-form-label">姓名</label>
  10.                             <divclass="layui-input-block">
  11.                               <inputname="fname"
    class="layui-input"type="text"placeholder="請輸入姓名"autocomplete="off"lay-verify="fname">
  12.                             </div>
  13.                           </div>
  14.                           <divclass="layui-form-item">
  15.                             <labelclass="layui-form-label">手機</label>
  16.                             <divclass="layui-input-block">
  17.                               <inputname="phone"class="layui-input"type="tel"autocomplete="off"placeholder="請輸入手機"lay-verify="phone">
  18.                             </div>
  19.                           </div>
  20.                           <divclass="layui-form-item">
  21.                             <labelclass="layui-form-label">郵箱</label>
  22.                             <divclass="layui-input-block">
  23.                               <inputname="email"class="layui-input"type="text"autocomplete="off"placeholder="請輸入郵箱"lay-verify="email">
  24.                             </div>
  25.                           </div>
  26.                           <divclass="layui-form-item">
  27.                             <labelclass="layui-form-label">單選框</label>
  28.                             <divclass="layui-input-block">
  29.                               <inputname="sex"title="男"type="radio"checked=""value="男">
  30.                               <inputname="sex"title="女"type="radio"value="女">
  31.                               <inputname="sex"title="保密"type="radio"value="密">
  32.                             </div>
  33.                           </div>
  34.                           <!--<divclass="layui-form-item layui-form-text">
  35.                             <labelclass="layui-form-label">普通文字域</label>
  36.                             <divclass="layui-input-block">
  37.                               <textareaclass="layui-textarea"placeholder="請輸入內容">請輸入內容</textarea>
  38.                             </div>
  39.                           </div>-->
  40.                           <divclass="layui-form-item layui-form-text">
  41.                             <labelclass="layui-form-label">內容</label>
  42.                             <divclass="layui-input-block">
  43.                               <textareaclass="layui-textarea layui-hide"name="contact"id="LAY_demo_editor"lay-verify="contact"></textarea>
  44.                             </div>
  45.                           </div>
  46.                           <divclass="layui-form-item">
  47.                             <divclass="layui-input-block">
  48.                               <buttonclass="layui-btn"lay-filter="demo2"lay-submit="">跳轉式提交</button>
  49.                               <buttonclass="layui-btn"lay-filter="demo1"lay-submit="">立即提交</button>
  50.                               <buttonclass="layui-btn layui-btn-primary"type="reset">重置</button>
  51.                             </div>
  52.                           </div>
  53.                         </form>


js驗證程式碼

  1. <script>
  2. layui.use(['form', 'layedit', 'laydate'], function(){  
  3.   var form = layui.form()  
  4.   ,layer = layui.layer  
  5.   ,layedit = layui.layedit  
  6.   ,laydate