<form id="form1" class="layui-form" action="提交路径" method="post">javascript
<div class="layui-form-item ">css
<label class="layui-form-label">成本预算 <span style="color: red; font-size: 20px">*</span>: </label>
<div class="layui-input-block">java
<input type="text" name="costbudget" lay-verify="required|validateMoney" placeholder="请输入" autocomplete="off" class="layui-input">
</div>
</div>正则表达式
</form>post
js文件ui
<script type="text/javascript">
layui.use('form', function () {
var form = layui.form;spa
//自定义表单验证(金额)
form.verify({
validateMoney: [
/^[+]{0,1}(\d+)$/ //正则表达式
,'金额只能为正整数' //提示信息
]
}); orm
//自定义表单验证(地址连接)
form.verify({
address: [
/^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/
,'请输入正确的地址连接,如:https://www.jd.com/'
]
});ip
</script>get
*注:使用本方法请先引入layui依赖的layu.js和layui.css
一个小白的分享