input框校验只能输入数字和小数点方法
// 只能输入数字且只有一位小数 proving(item) { // this.form[item] 是input的值 // 先把非数字的都替换掉,除了数字和. this.form[item] = this.form[item].replace(/[^\d.]/g, ""); // 必须保证第一个为数字而不是. this.form[item] = this.form[item].replace(/^\./g, ""); // 保证只有出现一个.而没有多个. this.form[item] = this.form[item].replace(/\.{2,}/g, ""); // 保证.只出现一次,而不能出现两次以上 this.form[item] = this.form[item] .replace(".", "$#$") .replace(/\./g, "") .replace("$#$", "."); let index = -1; for (let i in this.form[item]) { if (this.form[item] === ".") { index = i; } if (index !== -1) { if (i - index > 1) { this.form[item] = this.form[item].substring( 0, this.form[item].length - 1 ); } } }
随手保存下,下次方便使用
本文来自博客园,作者:zhupan,转载请注明原文链接:https://www.cnblogs.com/zhupanpan/p/12692691.html
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术