javascript - 大小数的 JavaScript 验证表单
问题描述
I have a form validated by a script, the value of the form cannot be greater than 5. But if you enter 5.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 the form is validated and the value is rounded, how can I do the validation with a large number of decimal places without rounded ?
解决方案
我通过简单地在点(逗号)之后拆分数字字符串来解决这个问题。在表格中输入极端数据后,小数部分得到验证
function validateY(inp) {
let elemY = ($('#y_set'))
let c = (inp.value.replace(',','.'))
c = c.split('.')
c = Number(c[1])
let val = Number((inp.value.replace(',','.')))
if ( isNaN(val) || typeof(val) != "number" || elemY.val()==="" ){
return false
}else if (val === 5 && c > 0) {
return false
}else if (val === -3 && c > 0) {
return false
}
return val <= 5 && val >= -3
}
c 变量 - (字符串拆分为整数和小数)。5和-3是表格中允许的极值
对不起,如果代码不好,我还在学习
推荐阅读
- c# - 如何在 Azure.Messaging.ServiceBus 中克隆消息,版本 = 7.1.2.0
- google-analytics - 计算每个事件在谷歌数据工作室中每个会话发生的平均次数
- python - python:python3中的~运算符功能是什么
- azure - 我们可以从 Azure Web PubSub 获取对话历史记录吗
- python - (python) 如果同一个程序已经在运行,如何拒绝代码执行?
- api - 导出 api 密钥环境变量:export API_KEY=${your_api_key}
- git - 想要使用 api 或 jenkins postBuildAction 中的脚本将 git commitId 关联到特定的 jenkins 构建
- api - 在 Laravel Blade 的“Enter”上打开“Google Maps API 键盘快捷键”弹出窗口
- android - Android 11 - 快速重新连接到 WiFi 网络
- typescript - 打字稿 - 翻译字符串打字解决方案?