当前位置:网站首页>Validate floating point input
Validate floating point input
2022-08-03 09:02:00 【my genius girlfriend】
Floating point input is based on integer validation,Divide the decimal into two parts by the decimal point,进行验证.
- . validint Add the corresponding by the decimal pointshell 文件引入对应的shell文件
#!/bin/bash
. validint
validfloat()
{
fvalue="$1"
if [ ! -z $(echo $fvalue | sed 's/[^.]//g') ] ; then
decimalPart="$(echo $fvalue | cut -d. -f1)"
fractionalPart="${fvalue#*\.}"
if [ ! -z $decimalPart ] ; then
if ! validint "$decimalPart" "" "" ; then
return 1
fi
fi
if [ "${fractionalPart%${fractionalPart#?}}" = "-" ] ; then
echo "Invalid floating-point number: '-' not allowed \ after decimal point" >&2
return 1
fi
if [ "$fractionalPart" != "" ] ; then
if ! validint "$fractionalPart" "0" "" ; then
return 1
fi
fi
else
if [ "$fvalue" = "-" ] ; then
echo "Invalid floating-point format." >&2 ; return 1
fi
if ! validint "$fvalue" "" "" ; then
return 1
fi
fi
return 0
}
if validfloat $1 ; then
echo "$1 is a valid floating-point value"
fi
exit 0
边栏推荐
猜你喜欢
随机推荐
安装mysql-workbench
箭头函数与普通函数的区别
Qt 下拉复选框(MultiSelectComboBox)(一) 实现下拉框多选,搜索下拉框内容
English Grammar - Adverbial Clauses
Using pipreqs export requirements needed for the project. TXT (rather than the whole environment)
IDEA的database使用教程(使用mysql数据库)
milvus
【收获合辑】k-NN与检索任务的异同+jupyter转pdf
【LeetCode】112.路径总和
多线程下的单例模式
分区分表(一)
qt使用mysql数据库(自学笔记)
Guava-字符串工具
Gauva的ListenableFuture
响应式布局经典范例——巨幅背景大标题
面渣逆袭:MySQL六十六问,两万字+五十图详解
系统io统计
软体按摩机器人驱动器的设计与仿真
并发之固定运行和交替运行方案
10 minutes to get you started chrome (Google) browser plug-in development