사용자 정의 폼 검사

8778 단어 layui
사용자 정의 금액 검사

<html>
<head>
    <meta charset="utf-8">
    <title> title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../js/layui/css/layui.css" media="all">
    
head>
<body>


<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend> legend>
fieldset>

<form class="layui-form" action="">

    <div class="layui-form-item">
        <label class="layui-form-label"> label>
        <div class="layui-input-inline">
            <input type="number" name="myMoney" lay-verify="require|validateMoney" placeholder=" "
                   autocomplete="off" class="layui-input">
        div>
        <div class="layui-form-mid layui-word-aux"> div>
    div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1"> button>
            <button type="reset" class="layui-btn layui-btn-primary"> button>
        div>
    div>
form>


<script src="../js/layui/layui.js" charset="utf-8">script>

<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
                , layer = layui.layer

        // 
        form.verify({
            validateMoney: function (value) {
                var result = validateMoney(value);
                if (result != "Y") {
                    return result;
                }
            }
        });

        // 
        form.on('submit(demo1)', function (data) {
            layer.alert(JSON.stringify(data.field), {
                title: ' '
            })
            return false;
        });
    });

    /**
     *  
     * @param money
     * @returns {*}
     */
    function validateMoney(money) {
        var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
        if (reg.test(money)) {
            return "Y";
        }
        return " , !";
    }
script>

body>
html>

좋은 웹페이지 즐겨찾기